Open cacs200281 opened 1 year ago
As you may have guessed from the long silence, the problem here is the question is lacking enough detail for the experts to help. Attaching a COMPLETE, REPRODUCIBLE (as in "download this file, run these commands, observe this weird thing") test case vastly improves the chance of you getting meaningful help. As it stands, we're left to kind of guess that there's some kind of memory allocation issue on one kind of original ESP32 board (https://makeradvisor.com/tools/esp32-dev-board-wi-fi-bluetooth/ ?") that's running code that might be ESP-IDF or might be Arduino and that has a self-conflicting definition of "upload" vs "download" (what direction should the data flow? From the phone to the board, or vice versa?) running some kind of protocol (http? https? ftp? raw sockets?) with unclear baselines (if we replace the ESp32 with a Real Computer, does this test case work?) and unknown versions of everything (Arduino? ESP-IDF? Browser? Curl?) and a hundred other things.
We dont' know what you've tried, what's worked, and what's failed. We don't know if this is sent chunked or streamed. We don't know if you've read (and understood) any of the doc at https://github.com/me-no-dev/ESPAsyncWebServer at all - particularly the sections of (Send|Respond).*Large
I could keep going, but hopefully I've made the point in a way that's educational and not insulting. When you're asking for help, you're trying to catch the attention of experts that can actually help you. (Probably for free, even...) If you can jump straight to a case they can copy/paste to their board, observe that "http://board/getfoo.html is empty but ...getfoo2.html is 65,534 bytes long..." you've given them something to attach to a debugger and engage internal knowledge.
Sorry if this sounds cranky, but the load is on you to provide a good question to capture the attention of the right experts. They may be less inclined to play 'hundred questions' or worse, guess at 98 of the questions and base an answer on an "incorrect" supposition.
I may not even be able to be the one to help, but hopefully I can inspire you to ask a question that's so awesome that The Right Person will recognize it and say "oh, did you set the FROBOZZ bit?", offer a link to the doc, and you'll slap your forehead, confirm the fix, thank the responder, and close the ticket a happy person.
Good luck on your way to happiness.
I encountered what appears to the same issue in that any file over about 5.5kb would not download. I was using code similar to this:
server_.on("/download", HTTP_GET, [this](AsyncWebServerRequest *request)
{
request->send(SD, "/path/to/file.json", "application/json", true);
});
After much googling I can across code that did word for large files as follows:
server.on("/download", HTTP_GET,
[](AsyncWebServerRequest *request)
{
String filename = request->getParam(param_download_path)->value();
Serial.println( "inputMessage - " + filename);
String inputMessage = "/logs/" + filename;
Serial.println("File to download :- " + inputMessage);
{
File file = LittleFS.open(inputMessage.c_str(), FILE_READ); // Replace LittleFS with SPIFFS if using SPIFFS
AsyncWebServerResponse *response = request->beginChunkedResponse("text/csv", [file](uint8_t *buffer, size_t maxLen, size_t total) mutable -> size_t
{
Serial.print("Max length: ");
Serial.println(maxLen);
// Tried sending less than max length
size_t length;
// Restrict chunk size so we don't run out of RAM
static const size_t max_chunk { 512};
if (max_chunk < maxLen)
{
length = file.read(buffer, max_chunk);
Serial.print("Length max_chunk < maxLen: ");
Serial.println(length);
}
else
{
length = file.read(buffer, maxLen);
Serial.print("Length max_chunk >= maxLen: ");
Serial.println(length);
}
if (length == 0)
{
file.close();
}
return length;
});
// Set response headers
response->addHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
request->send(response);
});
This works if I want to select download one file at a time but I have not got code the will download all files in directory.
Hi, @peterj43.
Isn't this essentially serveStatic() and related techniques described at
https://github.com/me-no-dev/ESPAsyncWebServer
Notably, this change assumes you're always sending from a file. Perhaps that's enforced elsewhere in the code, but seems worth questioning.
The use of a global static buffer isn't thread safe and takes 512 bytes is precious memory, even when this isn't used. I'd prefer to map the memory of we can, saving a copy, and allocating and freeing a buffer if we can't.
On the other hand, you appear to be successfully using LittleFS. Id be interested in hearing if you had any issues integrating that. I started that work a few times but never got into a finish line that I was happy with. Id be interested in cherry picking those PRs.
I'm doing some tests with an esp32 board(Doit Devkit V1) and when I try to dowload files with size up to 5.5Kb everything is ok. But when the file has a size > 5.5Kb the browser shows the attached info. I tried using Chrome/Edge from my PC and Chrome from my cell phone. Somebody can help me please? I'm a newbie in this area. Thanks in advance