Code Monkey home page Code Monkey logo

esp32-asyncwebserver-fileupload-example's Introduction

esp32-asyncwebserver-fileupload-example

This is hopefully a simple example to demonstrate how to upload a file to an ESP32 using the AsyncWebServer, saving the files on to SPIFFS and having a simple upload progress bar displaced.

There are various instructions around the place, but they were all confusing and it took a long time to figure out what was needed, I hope these examples help someone.

Example 1 - Single Webpage, File Listing, Simple Upload

  • single webpage
  • file listing button
  • file upload button

Example-02 is more complete and offers a better user experience, with this example there is no progress of file upload after clicking the upload button.


Example 2 - Single Webpage, Authentication, File Management, Upload with Progress Bar

  • web page authentication
  • single webpage
  • file listing button
  • file download button
  • file delete button
  • file upload button
  • reboot esp32 button
  • all done on a single web page that updates webpage elements using javascript


esp32-asyncwebserver-fileupload-example's People

Contributors

smford avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp32-asyncwebserver-fileupload-example's Issues

Files could neither be deleted nor downloaded - example 2

In the example 2 I could not download the uploaded file and could not delete the uploaded file.

I traced the issue to: line 99: if(!SPIFFS.exists(filename)
the filename is defined with: const char *fileName = request->getParam("name")->value().c_str(); (line 94)

I did a rather ugly workauround with the following code:

    char *cstr1 = (char*)malloc(strlen(request->getParam("name")->value().c_str())+1);
    strcpy(cstr1,"/");
    strcat(cstr1, fileName);
    if (!SPIFFS.exists(cstr1)){
    .
    .
     request->send(SPIFFS, cstr1, "application/octet-stream");
     .
    .
    SPIFFS.remove(cstr1);
    .
    .
    free(cstr1);

Memory leak in the example

In the first example the following handler generates a memory leak:

server->on("/upload", HTTP_POST, [](AsyncWebServerRequest *request) {
request->send(200);
}, handleUpload);

it should be written as

server->on("/upload", HTTP_POST, [](AsyncWebServerRequest *request) {
}, handleUpload);

Handling the response in the handleUpload function.

Otherwise request->send() clear the request while is still in use in the handleUpload() and then heap is never recovered....

Connection resets on more than 5-6 multiple files

Modifing to name="data[]" multiple> I cand send up to 5 or 6 files (4-5Kb each) or the connection resets.
I woud like to be able to send about 2-300 files, approx 1.5Mb total.
What is triggering the error?

Reboot button does not work

First, thank you very much for this great example. It works quite well, and fiited well into my project involving modifying an old jukebox, rewiring the old buttons and finally serve audio files to a sonos box. I did not use the SPIFF but added an SD card for more storage.

I used the more fancy 2nd example and noticed the reboot button does not work at all.

In webpages.h
Line 29:
document.getElementById("statusdetails").innerHTML = "Invoking Reboot ...";

Changed into:
document.getElementById("details").innerHTML = "Invoking Reboot ...";

BTW, the conversion to SD card was easy. First I changed all SPIFFS references to SD. The only thing with SD.exists() and SD.remove() is that it wants a "/" in front of the filename, so I made some minor changes for that in webserver.ino

Thanks again, very happy with this!

Cheers,
Frank

handleUpload is not being called from .on method to handle /upload request

Hi, how are you?, and thanks for this example.

I'm trying to apply your method to upload a file to the esp32 (in my case the content is JSON) but even tough the request is being done correctly to the esp32 then after receiving the request then the equivalent handleUpload in my code is not being called, I say this because none of the messages that I have in my implementation of handleUpload as you defined it here are displayed, I made this post in stackoverflow where I tell the problem.

I think all the arguments of handleUpload are automatically generated and passed to it by the .on method but I'm no sure. Can you help me with this?.

Thanks in advance ofr the help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.