Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void handleFileUpload(){ // upload a new file to the SPIFFS
- HTTPUpload& upload = server.upload();
- if(upload.status == UPLOAD_FILE_START){
- String filename = upload.filename;
- if(!filename.startsWith("/")) filename = "/"+filename;
- Serial.print("handleFileUpload Name: "); Serial.println(filename);
- fsUploadFile = SPIFFS.open(filename, "w"); // Open the file for writing in SPIFFS (create if it doesn't exist)
- filename = String();
- } else if(upload.status == UPLOAD_FILE_WRITE){
- if(fsUploadFile)
- fsUploadFile.write(upload.buf, upload.currentSize); // Write the received bytes to the file
- } else if(upload.status == UPLOAD_FILE_END){
- if(fsUploadFile) { // If the file was successfully created
- fsUploadFile.close(); // Close the file again
- Serial.print("handleFileUpload Size: "); Serial.println(upload.totalSize);
- server.sendHeader("Location","/html/success.html"); // Redirect the client to the success page
- server.send(303);
- Serial.print("User-specified file path: ");
- Serial.println(server.arg("file_path"));
- } else {
- server.send(500, "text/plain", "500: couldn't create file");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement