-
Notifications
You must be signed in to change notification settings - Fork 116
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
totalSize and currentSize return both the same value, the value of currentSize. #223
Comments
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
Hello. Any solution? |
@ayushsharma82 @hash6iron @Tamairon : there is a bug in ElegantOTA. Here is how the upload works behind.... The callback signature is: [&](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) The internal code is: void AsyncWebServerRequest::_handleUploadByte(uint8_t data, bool last) {
_itemBuffer[_itemBufferIndex++] = data;
if (last || _itemBufferIndex == RESPONSE_STREAM_BUFFER_SIZE) {
// check if authenticated before calling the upload
if (_handler)
_handler->handleUpload(this, _itemFilename, _itemSize - _itemBufferIndex, _itemBuffer, _itemBufferIndex, false);
_itemBufferIndex = 0;
}
}
The callback is called:
So:
With ESpAsyncWS the code is doing: if(len){
if (Update.write(data, len) != len) {
return request->send(400, "text/plain", "Failed to write chunked data to free space");
}
_current_progress_size += len;
// Progress update callback
if (progressUpdateCallback != NULL) progressUpdateCallback(_current_progress_size, request->contentLength());
} or with WebServer: } else if (upload.status == UPLOAD_FILE_WRITE) {
if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
#if UPDATE_DEBUG == 1
Update.printError(Serial);
#endif
}
_current_progress_size += upload.currentSize;
// Progress update callback
if (progressUpdateCallback != NULL) progressUpdateCallback(_current_progress_size, upload.totalSize);
}
Generally speaking, whether in AsyncWS or Arduino WebServer, the file upload callback is called during the multipart parsing of the request so the total file size is not yet known. The callback of ElegantOTA is wrong and should be:
instead of:
We only know the current growing size, not the final one. And relying on |
Solution There is a solution though. The solution is to calculate the file size in javascript and when sending the multipart upload, add a header to the request, for example for 2Mb file:
Headers are always parsed BEFORE the body. This approach would fix the issue and allow to keep the callback as-is. |
@mathieucarbou Is it possible to implement in the library? or that is a local solution? How can I apply this solution to my code? |
It requires a UI change so only @ayushsharma82 can fix it for the oss version. |
Yeah, OSS version is due for an update. I'll fix it with next release, along with #229, but it will take some time. |
Hi,
I try to use "totalSize" to know the size of the file to be uploaded and "currentSize" to know how many bytes were uploaded, but currentSize and totalSize always return the same value, bytes uploaded, then is not possible to know the size of the file previously.
The version that I'm using is, "ElegantOTA @ 3.1.5"
The text was updated successfully, but these errors were encountered: