esp32-asyncwebserver-fileupload-example icon indicating copy to clipboard operation
esp32-asyncwebserver-fileupload-example copied to clipboard

Files could neither be deleted nor downloaded - example 2

Open janphoffmann opened this issue 2 years ago • 5 comments

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);

janphoffmann avatar Nov 07 '22 21:11 janphoffmann

Same issue here, did this modification:

char dataPath[120] = {0}; memset(dataPath, 0x0, sizeof(dataPath)); strcpy(dataPath, gifFile.path());

and replaced all fileName to dataPath

That was my work around.

viniciusro avatar Dec 27 '22 19:12 viniciusro

Thank you @janphoffmann & @viniciusro , I suspect libraries have changed since this was first published which is causing this. When I get time over the next couple weeks I will test and update.

smford avatar Jan 13 '23 22:01 smford

I remplaced this line: const char *fileName = request->getParam("name")->value().c_str(); with this: String fileName = "/"+String(request->getParam("name")->value() );

ens4dz avatar Apr 01 '23 23:04 ens4dz

Works like a charm. PR.

kbhuinfo avatar Jun 15 '23 09:06 kbhuinfo

In my case, only '/' was missing before the file name.

if (!FFat.exists(String('/') + fileName)) {

https://github.com/smford/esp32-asyncwebserver-fileupload-example/blob/c47a5c510c6036bfeb8c20f549bb2874819ea5c4/example-02/webserver.ino#L99


request->send(FFat, String('/') + fileName, "application/octet-stream");

https://github.com/smford/esp32-asyncwebserver-fileupload-example/blob/c47a5c510c6036bfeb8c20f549bb2874819ea5c4/example-02/webserver.ino#L106


FFat.remove(String('/') + fileName);

https://github.com/smford/esp32-asyncwebserver-fileupload-example/blob/c47a5c510c6036bfeb8c20f549bb2874819ea5c4/example-02/webserver.ino#L109

rtek1000 avatar Mar 18 '24 02:03 rtek1000