[SOLVED] Does anyone know how to upload files into the ESP32 using a browser and AsyncWebServer ?

GeorgeFlorian1
Posts: 160
Joined: Thu Jan 31, 2019 2:32 pm

[SOLVED] Does anyone know how to upload files into the ESP32 using a browser and AsyncWebServer ?

Postby GeorgeFlorian1 » Thu Jul 04, 2019 11:55 am

Hello !

So I am trying to upload files to the ESP32 using this server and a browser and I can't figure it out...

I got this handler:

Code: Select all

void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
  if(!index){
    logOutput((String)"UploadStart: " + filename);
  }
  for(size_t i=0; i<len; i++){
    Serial.write(data[i]);
  }
  if(final){
    logOutput((String)"UploadEnd: " + filename + "," + index+len);
  }
}
And this handler inside setup():

Code: Select all

      server.on("/upload", HTTP_POST, [](AsyncWebServerRequest *request) {
        request->send(200);
      }, handleUpload);
And this is in HTML:

Code: Select all

	<form method = "POST" action = /upload>
		<input type="file" name="data" data-multiple-caption="{count} files selected" multiple/>
		<input type="submit" name="upload" value="Upload" title = "Upload Files">
	</form>
I press on Upload button and it sends me to a blank page `request->send(200);`, but it doesn't upload my file.
I know I am doing something wrong, but I have no idea what. I couldn't find anything useful in the examples or on Google. Maybe because I don't know what to search for.

Any ideas ? What is missing ?

EDIT:

I have also tried the following handler and this time it returned "not found".

Code: Select all

      server.on("/upload", HTTP_POST, [](AsyncWebServerRequest *request) {
        if(request->hasParam("data", true, true) && SPIFFS.exists(request->getParam("data", true, true)->value()))
          request->send(200, "", "UPLOADED: "+request->getParam("data", true, true)->value());
      });
Last edited by GeorgeFlorian1 on Tue Jul 09, 2019 8:44 am, edited 1 time in total.

User avatar
rudi ;-)
Posts: 1728
Joined: Fri Nov 13, 2015 3:25 pm

Re: Does anyone know how to upload files into the ESP32 using a browser and AsyncWebServer ?

Postby rudi ;-) » Sun Jul 07, 2019 7:55 pm

hi
it looks like you solved this for you,
also you added the option to delete files.
does it run now like you wanted?

best wishes
rudi ;-)
-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

GeorgeFlorian1
Posts: 160
Joined: Thu Jan 31, 2019 2:32 pm

Re: Does anyone know how to upload files into the ESP32 using a browser and AsyncWebServer ?

Postby GeorgeFlorian1 » Tue Jul 09, 2019 8:43 am

rudi ;-) wrote:
Sun Jul 07, 2019 7:55 pm
hi
it looks like you solved this for you,
also you added the option to delete files.
does it run now like you wanted?

best wishes
rudi ;-)
Yes, it works wonders, thanks for asking !

Who is online

Users browsing this forum: Baidu [Spider], username and 125 guests