vapor/vapor

Stream not work correctly

i-fire1773 opened this issue · 2 comments

Stream not correct work for video/image
I use project
VaporUploads-main.zip
When I send file type pdf it work correct? and I can open it, but when I send other type of file it send, but I can't open it because
image
image file I download from internet

vzsg commented

There's nothing wrong with Vapor or your project, but the way you upload the image is not compatible with the code. The route expects a HTTP POST request whose body is the image data directly, not part of a multipart form.


Opening the image file in a hex editor quickly reveals the issue. Notice the highlighted area: that's the header from a multipart file upload, which was saved into the image file directly.

image

If I delete this, and the footer area at the end, the image opens up fine (although there don't seem to be any rabbits on it).


Now, how to do multipart uploads without loading the complete body into memory is an interesting challenge for which I don't have an answer. Maybe someone else will.

@vzsg Multipart should in theory be streamable, but it's not currently supported. The caveat is that you'll need to consume the parts in order.