Search code examples
javarestmime-typesfeign

Why to use multipart/form-data over application/octet-stream?


I'm not clear what they are and the less I can see when to use them.

In example I have REST client and I want to send one file(.zip file), what exactly happens if I use any of those type

  • application/octet-stream is I guess equal to application/zip, which is just to give hints to other side about data transfered, file is somehow encoded
  • multipart/form-data somehow breaks the data and you can pass "multiple data" with it's specific mime type, file is somehow encoded and is part of one part of the multipart request. In this case I'm not sure how to tell Feign client request to be multiparted with that exact part to be octet-stream

But if I want to send only one file what exectly multipart gives me that octet-stream doesn't have?

In both requests the whole file is somehow encoded inside, right? How does the processing differ. I don't see any advantage. Why Feign client tutorials use multipart or is it just common practice?

Further more I have found that somehow you need to also enable the whole multipart circus in the server to be able to receive it. So what is the point?


Solution

  • In the past, I used application/zip or application/octet-stream for .zip file. For your case, either one of these headers should work fine.

    Per another commenter -

    "Multipart is for sending multiple parts (e.g. form fields and some files) in one single HTTP request, with file name and encoding specified. It does not split huge files into parts. One file is still just one part in a multipart request. HTTP headers can be included in both cases. "

    The following threads may also provide more context:

    Mutipart form data

    URL encoded multipart form data