-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Issue loading files w/SPIFFS (ERR_CONTENT_LENGTH_MISMATCH) #2121
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
Comments
Hi, Very nice code. I have some suggestions; 1-sometimes mDNS makes trouble , reboot your router,pc and esp ---> because "ws://myword.local" in your webpage kills your connection so try to use;
2-Dont use font css - remove them from header Bonus here :) Remove 3. line from handleFileRead
add this to your setup
add handleFileRead2
UPDATE: Merge all of your js files to only one js file and also css files to one css file I hope this helps. |
@kiralikbeyin I don't know why so much of my code isn't being shown the way it should be in this new reply, I used the code tags :( alright so I ended up switching over to that modified version of the library in the meantime since I made this post, and unfortunately I don't think I can apply your current solution directly since it relies on the original library. Sorry but is there any chance that we could find a way to apply your solution to my new code? Here is the relevant set of functions: ` class SPIFFSEditor: public AsyncWebHandler {
};` I can see one of the lines you asked to remove is in here: // if (path.endsWith("/")) path += "index.htm"; And here is my new setup as well: `void setup(){ IPAddress ip(192, 168, 1, 16); //Initialize Serial Connections //Initialize File System //Initialize WiFi Connection (Modified Server Library Code)
} //NEW server.serveStatic("/fs", SPIFFS, "/"); server.on("/heap", HTTP_GET, [](AsyncWebServerRequest *request){ server.onNotFound([](AsyncWebServerRequest *request){
});
});
}); //Setup a timer for all WiFi status updates Sorry again and thank you so much for your assistance. |
There is nothing to do with esp code. I think all problem is reading a lot of files (size not important) More count more trouble. Merge all of your js files to only one js file and also css files to one css file this will absolute solution. If you are using font awesome or gly of bootstrap they are raising the count of read files when startup. So don't use them now.(ERR_CONTENT_LENGTH_MISMATCH) +Some links in css code may search other css files or font files in dir, this is why you got this error. Also try safari,chrome and firefox for console logs, they are giving different logs. Remember to clear browser cache before trusting your code. +I am not using Async lib but it will work for you. |
@kiralikbeyin Alright I merged three of my css files into one and I took a gauge library I was using in js and merged it with my general js file. However, there's another js file that I've had to include at the end of the file because it references elements in the html and creates elements that load at the start of the page. I'm not sure how to include this with my other js because it has to load later? `var voltageGauge = new Gauge({ voltageGauge.draw();` |
Here Jquery before bootstrap, at the end some custom code. You can also directly paste js code before body close
If you can't merge It is not a rule to use 1 js file, use it like;
less file more performance. Don't try to put css code to js file. Only merge css to css , js to js. |
Alright so I seemed to have mostly solved this issue by using the modified library, compressing my code, and removing jQuery entirely. I still get errors every once in a while, but these appear to be unavoidable and everything works most of the time. @kiralikbeyin I compressed all my scripts into one and posted it at the end of the body as you suggested, which seems to work. Thanks for all your help. |
@Th3On3Fr33man your description starts with ESP8266Webserver, but then later you discuss ESPAsyncWebserver.
|
Closing due to lack of feedback and age. |
I have a slightly different problem, but its solution may suit you. |
Basic Info
Hardware
Hardware: ESP-8266
Core Version: 2.2.0
Description
Alright so I've been looking into this for the past two days and I still feel like I'm getting nowhere.
I recently started using the SPIFFS File System for Arduino development on an HUZZAH ESP8266 like the FSBrowser.ino example, and while it's been great in terms of separating code, as my code continues to grow it has not been great in terms of stability.
Ever since I began adding more and more javascript, I began to have errors pop up for various files, whether it's my HTML/CSS/JS, and the primary error I see is ERR_CONTENT_LENGTH_MISMATCH.

So after that happened I began examining the handleFileRead() function that I copied from the FSBrowser.h example and after testing various print statements it seems the hangup occurs within this line:
size_t sent = server.streamFile(file, contentType);
So from there, I went into ESP8266WebServer.h and found the streamFile() function. Once inside this function, I discovered this line:
return _currentClient.write(file, HTTP_DOWNLOAD_UNIT_SIZE);
From this I deduced two things:
So I followed the trail to this function: size_t WiFiClient::write(const uint8_t *buf, size_t size).
Now this doesn't quite match because the first parameter of the write() function that was called is of type File, while the first parameter of this function is uint8_t, but I placed some print statements within here nonetheless and they execute as the files are being loaded so I believe I've found the correct function.
However, now I'm at a loss as to how to continue fixing the problem from here, since there is only a recursive call and the error seems to occur because the culprit file doesn't finish loading (at least according to chrome debugger's network tab).
As you can see, the style.css file is listed as being 3 kilobytes, which is of course wrong: my css file is 27 kilobytes.
So it appears that there's an issue loading files (this is not exclusive to the css file, it has happened with my javascript files as well and appears to be random). I have tried minifying all the files and it hasn't fixed the issue; so I could really use some help determining how to fix this.
Now I received some advice from another source to try using this library, which is a modified version of the FSBrowser code: https://github.com/me-no-dev/ESPAsyncWebServer
At first this seemingly had fixed all my problems. The code was running stable with none of the previous issues popping up. But since switching to that library, I've run into a myriad of new issues:
And the strangest thing happened, where it appears some of the code was missing?

If you look at the red highlighted line in that photo, you can see that in the middle of the removeClass() statement, it stops spelling out the class (which is "deactiveSect") and starts a completely different if statement further down in the code.
And yet here's the same portion of code on the server currently:
You can see it seemingly merged lines 66 and 70.
So while the version of the FSBrowser code that I was using couldn't handle the level of code I was working with, I'm failing to see how I can afford to use this modified library if this myriad of issues keeps occurring.
Settings in IDE
Module: Adafruit Huzzah ESP8266
Flash Size: 4MB/3MB
CPU Frequency: 80Mhz
Flash Mode: ??? (Unsure where to find this)
Flash Frequency: ??? (Unsure where to find this)
Upload Using: ??? (Unsure where to find this...I'm using a USB to FTDI cable so...Serial?)
Reset Method: ??? (Unsure where to find this...I'm using the reset button on the card itself?)
Upload speed: 115200
Port: COM8
Programmer: AVRISP mkII
Here's the source for the rest of my code (with the original FSBrowser library):
Primary ino file
Primary ino header file
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: