Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files could neither be deleted nor downloaded - example 2 #4

Open
janphoffmann opened this issue Nov 7, 2022 · 5 comments
Open

Files could neither be deleted nor downloaded - example 2 #4

janphoffmann opened this issue Nov 7, 2022 · 5 comments

Comments

@janphoffmann
Copy link

janphoffmann commented Nov 7, 2022

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);
@viniciusro
Copy link

viniciusro commented Dec 27, 2022

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.

@smford
Copy link
Owner

smford commented Jan 13, 2023

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.

@ens4dz
Copy link

ens4dz commented Apr 1, 2023

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

@kbhuinfo
Copy link

Works like a charm. PR.

@rtek1000
Copy link

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

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


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

request->send(SPIFFS, fileName, "application/octet-stream");


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants