0

i want to upload a file from my pc to the esp2966 webserver with sd card. all works fine. But i want to transmit some extra data from a input form field.

The Upload works good. in the browser console i can see that the firstname is transmitted. But in the server.arg are no arguments received. What is wrong?

Here is my Code:

server.on("/fupload",  HTTP_POST,[](){ server.send(200);}, handleFileUpload);
...
..
.
void handleFileUpload(){ 
  String firstname = server.arg("vorname");
  Serial.println("Vorname: " +firstname);
  HTTPUpload& upload = server.upload();
  if (upload.status == UPLOAD_FILE_START) {     
    String filename = dir_name +"/" + upload.filename; 
    uploadFile.open((char *)filename.c_str(), FILE_WRITE);     
     } else if (upload.status == UPLOAD_FILE_WRITE) {     
      if (uploadFile.isOpen()) {       
        uploadFile.write(upload.buf, upload.currentSize);       
        else if (upload.status == UPLOAD_FILE_END) {     
          if (uploadFile.isOpen()) {       
            uploadFile.close();       
            webpage = "";
            append_page_header();
            webpage += F("<h3>File was successfully uploaded</h3>"); 
            webpage += F("<h2>Uploaded File Name: "); webpage += upload.filename+"</h2>";
            webpage += F("<h2>File Size: "); webpage += file_size(upload.totalSize) + "</h2>"; 
            webpage += F("<a href='/dir'>&lArr;[Back]</a><br><br>");
            server.send(200,"text/html",webpage);              
          }  
        }
      }
   }
}

here the html for upload

<FORM action='/fupload' method='post' enctype='multipart/form-data'>
  <input type="file" name="Datei" id="fileInput">
  <input type="text" name="vorname" value="TEST">
  <button type='submit'>Upload File</button>
</FORM>

EDIT: if i change this line

server.on("/fupload",  HTTP_POST,[](){ server.send(200);}, handleFileUpload);

to this:

server.on("/fupload", HTTP_POST, handleFileUpload);

Then the server.arg works but the upload does not work. Why? How can i solve this problem?

  • sorry, this does not help. – Pascal May 24 at 8:10
  • i have made an edit on my post. if i change this line server.on("/fupload", HTTP_POST,[](){ server.send(200);}, handleFileUpload); to this: server.on("/fupload", HTTP_POST, handleFileUpload); Then the server.arg works but the upload does not work. Why? How can i solve this problem? – Pascal May 24 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.