File upload: data past the boundary end
Hello, I noticed a problem with the upload of files. I used the code in the example at the readme page:
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
if(!index){
Serial.printf("UploadStart: %s\n", filename.c_str());
}
for(size_t i=0; i<len; i++){
Serial.write(data[i]);
}
if(final){
Serial.printf("UploadEnd: %s, %u B\n", filename.c_str(), index+len);
}
}
On the client side a form that submits the file to upload looks like this:
<form action="upload" method="POST" enctype="multipart/form-data">
<input type="file" required name="path">
<input type="submit" name="_submit" value="Upload">
</form>
so the browser sends to the server the following data:
`Content-Type: multipart/form-data; boundary=---------------------------109992776831753 Content-Length: 1191
-----------------------------109992776831753 Content-Disposition: form-data; name="path"; filename="index.htm" Content-Type: text/html
...(omitted data for brevity)....-----------------------------109992776831753 Content-Disposition: form-data; name="_submit"
Upload -----------------------------109992776831753-- `
The intended data to be received should be limited to the part after the two carriage return and before the following boundary marker, however the actual data returned by the function overflow. This is what the function put into the file:
`
...(omitted data for brevity).... /body>-----------------------------109992776831753 Content-Disposition: form-data; name="_submit"
Upload`
Submitted file size: 897 bytes, stored file: 1001 bytes.
2016.07.19 - UPDATE:
I have tested with a modified HTML code to submit the file in a way that just the file field is submitted pulling out the from the form:
<form id="ff" action="upload" method="POST" enctype="multipart/form-data">
<input type="file" required name="path"></form>
<button type="button" onclick="document.getElementById('ff').submit();" >Upload</button>
This time the file is uploaded missing the final part, or likely saving only the first portion of about 880 bytes, missing the final 17 or so bytes.
After reverting to the previous form, I also tried to remove the name attribute from the input tag of type submit to see what happen, and the application simply crashes (the stack is output via serial monitor).
UPDATE 2:
Crash happens when the browser send a whole block of data larger than a given amount. Example, some time it sends a first chunk of 884 bytes followed by a second final chunk of 1254 bytes, and this is completed succeessfully (though with the spurious chunk appended); some time it sends a whole block of 2139 bytes and in this case the server crashes. Note the 1 byte difference. Crash happens at exit of the upload handling function.
interesting... what is your OS/Browser?
My system is Win7 64bit pro SP1 and Browser is Firefox 43 (well, it need to be updated but I'm lazy :) ). If you want I can provide you the full body and headers of the request in an attached text file. I use the browser's debugger tools to retrieve these data.
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
[STALE_DEL] This stale issue has been automatically closed. Thank you for your contributions.