3

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?

Zveratko
  • 2,663
  • 6
  • 35
  • 64

1 Answers1

1

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

CEH
  • 5,701
  • 2
  • 16
  • 40
  • 1
    But I do not see the reason why multipart can handle bigger data. I will check specification as to see if there are any limits. And what about efficiency are both equal? Is there some streaming in place for multipart? – Zveratko Sep 26 '19 at 17:30
  • when adding a file using `multipart/form-data`, a `boundary` header is automatically added as well, which is used to separate the multiple parts of the data. you don't do anything different on your end, when using an engine like `Postman`, if you add `multipart/form-data`, it will automatically split up the file and set the `boundary` header for you. the file gets broken up into parts – CEH Sep 26 '19 at 17:35
  • I have seen only exmples with file per part. But anyway what is the advantage to split file in parts. Are the parts sent separately vs. octet stream sent at once? – Zveratko Sep 26 '19 at 17:45
  • yes, that's correct. you can use multipart for just one file. multipart is usually used in HTML forms when a file and other information besides the file is being submitted as well. the advantage is that, if it's a very large file, multipart will handle the request more efficiently. however, if it's a small file, or you are only submitting a file & no additional info, octet-stream is more efficient, because less work is done. – CEH Sep 26 '19 at 17:52
  • I will really appreciate extact details about the efficiency. What is ment by big file? Is 80MB big enough to bother with multipart? So why it is so widely used. Even Feign docs uses directly multipart without questioning. – Zveratko Sep 26 '19 at 17:58
  • because you can send more than just a file with it. for example if you are filling out an online job application, with your name, address, etc., and you have to attach your resume as a file, that is multipart formdata because it takes file input in addition to plain text input. I have personally seen 100mb limit when using application/octet-stream, but that may have been application-specific. – CEH Sep 26 '19 at 18:02
  • 1
    For REST API this reasoning is out of question. Will stay with octet-stream in my case. – Zveratko Sep 26 '19 at 18:03
  • 1
    That sounds like the right approach, multipart is usually for context of HTML web developer accepting a form input. if my answer & discussion has helped you, you are welcome to accept this answer. – CEH Sep 26 '19 at 18:09
  • 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. – TimTIM Wong Aug 16 '21 at 03:09
  • I have edited my answer to provide this context, thanks @TimTimWong! – CEH Aug 23 '21 at 17:55