How to handle chunked uploads correctly
I'm currently writing a server application using cpp-httplib. I'm having some issues regarding the file upload.
For testing I got a very simple HTML form, that was working correctly with an old version of an existing server application:
<form method="post" id="upload_form" enctype="multipart/form-data">
<table>
<tr><td>Path_Server:</td><td><select name="Path_Server"><option>TEMP</option></select></td></tr>
<tr><td>OVERWRITE:</td><td><select name="OVERWRITE"><option>TRUE</option><option>FALSE</option></select></td></tr>
<tr><td colspan="2"><input type="file" name="File" /></td></tr>
</table>
<input type="submit" value="Upload_File" onclick="createURL('upload_form', 'Upload_File')" />
</form>There you can select a file, that is sent to the server as POST request.
First I tried this approach: https://github.com/yhirose/cpp-httplib#multipartform-data-post-data That works well. The file must not exceed the size defined with set_payload_max_length, otherwise the request will be rejected. That's fine, but the file is loaded entirely into memory, which I'd like to avoid.
So I also tried this one: https://github.com/yhirose/cpp-httplib#receive-content-with-a-content-receiver Basically that also works well, because I get the file in pieces of 16 kB. But I'm having trouble checking the file size. If the uploaded file exceeds the size defined with set_payload_max_length, the request is not rejected, but I only get the first part of the file. I didn't find the file size in the headers or other parts of the data structs. Is there some way to check the complete file size? Or to get the rest of the file from the client (if that's possible with this HTML form)?
Source: yhirose/cpp-httplib