I have a project that needs to use the SD card as well as SPIFFS. There is known conflict of name File being declared in both library's.
I found a few pages about this, and tried the solution suggested here:
But, that does not work for me. I still get the error.
This is the snippet of code that handles my SPIFFs files (I believe), and I have added the fs:: as suggested.
Still doesn't compile
bool handleFileRead(String path) { // send the right file to the client (if it exists)
Serial.println("handleFileRead: " + path);
if (path.endsWith("/")) path += "index.html"; // If a folder is requested, send the index file
String contentType = getContentType(path); // Get the MIME type
String pathWithGz = path + ".gz";
if (SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)) { // If the file exists, either as a compressed archive, or normal
if (SPIFFS.exists(pathWithGz)) // If there's a compressed version available
path += ".gz"; // Use the compressed verion
fs::File file = SPIFFS.open(path, "r"); // Open the file
size_t sent = server.streamFile(file, contentType); // Send it to the client
file.close(); // Close the file again
Serial.println(String("\tSent file: ") + path);
return true;
}
Serial.println(String("\tFile Not Found: ") + path); // If the file doesn't exist, return false
return false;
}
Anyone have any suggestions?
I wish someone would make an I2C SD card module! Would save quite a lot of grief
Just as you get your head around something, they change it.
Nothing comes up in Library manager (for esp8266, only for ESP32). I'll have to go looking for the library and an example then
Well apparently all you need to change all instances of SPIFFS to LittleFS.
Did that, it complies but now can't find any files. It says SPIFFS doesn't support directories, yet my files are in directories and it worked fine.
Trouble is, I don't really understand all of the SPIFFS file system (it's lifted from a piece of code online), so I am not exactly sure what the problem is.
Anyway, two options... go back to SPIFFS, as at least that works..... or tidy my code, remove any bits that should not be seen by others and post it in here. Hmm
It says SPIFFS doesn't support directories, yet my files are in directories and it worked fine.
I believe that SPIFFS "directories" are really just filenames so although /dir1/file1.txt may look like a file named file1.txt in a directory named /dir1 it is, in fact, a file named /dir1/file1.txt
I may be wrong, but using SPIFFS can you list the files in a directory ?
Its all working with LittleFS now.
Before, I had sub directories in my data folder for JS,CSS,IMG,TXT etc.
Now, they are all just lumped into the data folder together. Not as tidy in my opinion, and if I spent some time on it, I could probably work out why I have lost the sub-file ability.
I also had to remove the directory addresses from my index.html file.
I have to say, its actually slower/same loading the files to the webpage than the original SPIFFS, so I have not seen any advantage yet.
My LittleFS initialisation is:
void startLittleFS() { // Start the LittleFS and list all contents
LittleFS.begin();
Serial.println("LittleFS started. Contents:");
{
Dir dir = LittleFS.openDir("/");
while (dir.next()) { // List the file system contents
String fileName = dir.fileName();
size_t fileSize = dir.fileSize();
Serial.printf("\tFS File: %s, size: %s\r\n", fileName.c_str(), formatBytes(fileSize).c_str());
}
Serial.printf("\n");
}
}
This fails to find sub directories within the data folder
My original SPIFFS serving code is:
bool handleFileRead(String path) { // send the right file to the client (if it exists)
Serial.println("handleFileRead: " + path);
if (path.endsWith("/")) path += "index.html"; // If a folder is requested, send the index file
String contentType = getContentType(path); // Get the MIME type
String pathWithGz = path + ".gz";
if (LittleFS.exists(pathWithGz) || LittleFS.exists(path)) { // If the file exists, either as a compressed archive, or normal
if (LittleFS.exists(pathWithGz)) // If there's a compressed version available
path += ".gz"; // Use the compressed verion
File file = LittleFS.open(path, "r"); // Open the file
size_t sent = server.streamFile(file, contentType); // Send it to the client
file.close(); // Close the file again
Serial.println(String("\tSent file: ") + path);
return true;
}
Serial.println(String("\tFile Not Found: ") + path); // If the file doesn't exist, return false
return false;
}
I will decode it line by line later and see if I can determine the issue.