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

SPIFFSEditor not displaying file contents on ESP32 with LittleFS #1210

Closed
steff393 opened this issue Sep 17, 2022 · 7 comments
Closed

SPIFFSEditor not displaying file contents on ESP32 with LittleFS #1210

steff393 opened this issue Sep 17, 2022 · 7 comments

Comments

@steff393
Copy link

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?

@blazoncek
Copy link

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.

@slimline33
Copy link

slimline33 commented Sep 27, 2022

The same problem here on my esp32 wroom.

image

the workaround does help!

@steff393
Copy link
Author

steff393 commented Oct 3, 2022

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.

@blazoncek
Copy link

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

@Aircoookie
Copy link

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.

@silk-indus
Copy link

silk-indus commented Oct 9, 2022

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

steff393 added a commit to steff393/ESPAsyncWebServer that referenced this issue Oct 10, 2022
@steff393
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants