Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

SPIFFSEditor not displaying file contents on ESP32 with LittleFS #1210

Closed

Description

@steff393

Hi,
thanks for this great library. I used it a lot on ESP8266. But now with ESP32 and LittleFS I found that the SPIFFSEditor doesn't display the file contents (only the file names on the left frame).
I got the error message:
[E][vfs_api.cpp:29] open(): myFile.txt does not start with /

The following change (i.e. adding the "/" in front of the filename) fixes this behavior:

request->_tempFile = _fs.open(request->arg("edit"), "r");

request->_tempFile = _fs.open(String("/") + request->arg("edit"), "r");

But I'm not sure if this is really the solution or only a quick workaround. What is your opinion?

Activity

  1. blazoncek commented on Sep 19, 2022

    @blazoncek

    I have noticed the same behaviour, though the fork we use (from @Aircoookie) works correctly on ESP32 but fails on ESP32-S2 and ESP32-S3.

  2. slimline33 commented on Sep 27, 2022

    @slimline33

    The same problem here on my esp32 wroom.

    image

    the workaround does help!

  3. steff393 commented on Oct 3, 2022

    @steff393
    Author

    After I had to introduce that "/" into multiple different places, I searched for a more generic approach:
    It now works also, when I only introduce a

    #ifdef ESP32
            output += "/";
    #endif
    

    here in between line 465 and 466:

    output += "file";
    output += "\",\"name\":\"";
    output += String(entry.name());
    output += "\",\"size\":";
    output += String(entry.size());

    This makes the filenames in the left frame of the SPIFFSEditor being displayed as "/index.html" instead of "index.html" and also the subsequent actions like Save, Delete, etc. use then the correct filename including "/".

    So from my point of view this could be a real solution.

    However I don't yet understand, why it's working in Aircookies fork. So there might be also another solution.

  4. blazoncek commented on Oct 3, 2022

    @blazoncek

    @steff393 You may want to use '/' instead of "/".

  5. Aircoookie commented on Oct 4, 2022

    @Aircoookie

    Thank you for finding what seems like a good solution!
    Note that at least for my fork/environment, filenames correctly include / as is, so your proposed change makes it //, which appears to work fine, but feels hacky.

    My hunch is that the LittleFS library by lorol returns filenames with leading / while the version built into the (recent) ESP32 arduino core does not.
    Instead of a define, I just added a check for leading slash to my fork (v2.0.7), seems to work well.

  6. silk-indus commented on Oct 9, 2022

    @silk-indus

    Hi to all.
    This has still one problem. The files are correctly edited and viewed in sub-directories when modified edit.htm.gz is used. Unfortunately I was unable to view/edit file using of SPIFFSEditor in subdir.
    SOLVED: I just put the path to the li elements of the files in the file list (edited was a copy of the file edit.htm.gz).

  7. steff393 commented on Oct 10, 2022

    @steff393
    Author

    I digged a little deeper, to find out, why entry.name() is returning the filename without '/', while on the other hand _fs.open() insists on the '/'. Because in the end, both functions come from the same source module, so I'd expect they should behave consistent:
    VFSFileImpl::name()
    VFSFileImpl::open()

    name() calls then the function pathToFileName(path()), which is returning only characters after the last '/' in the file path (i.e. it removes the slash).

    But there is also another function path() in vfs_api.cpp, which returns the full path and filename including the slash(es).

    Therefore I think the best solution would be:

    #ifdef ESP32
            output += String(entry.path());
    #else
            output += String(entry.name());
    #endif
    

    On my system it works well and I'm going to raise a PR accordingly.
    Unfortunately path() is not existing in ESP8266, so the #ifdef seems necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions