multipart/form-data vs application/octet-stream

HttpPostHttp Upload

Http Problem Overview


I'm creating a simple REST API for uploading files. From other API's I found they use "multipart/form-data" content type. But for me, it looks like "application/octet-stream" is much simpler.

If I don't intend to send any more form data with the file is there any reason to use "multipart/form-data" and not "application/octet-stream" ?

Http Solutions


Solution 1 - Http

While you don't intend to send any other data together with the file right now, multipart/form-data would give you the possibility to add additional data later on if this is required (without breaking compatability).

Also multipart/form-data would make it possible to access the REST API directly by submitting an HTML form (see https://stackoverflow.com/a/4526286/693140).

Your API could however support both types by using the client's content type header to distinguish between them.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlevkView Question on Stackoverflow
Solution 1 - HttpStefan KöglView Answer on Stackoverflow