Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multipart/form-data vs application/octet-stream

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" ?

like image 964
levk Avatar asked Mar 30 '15 13:03

levk


People also ask

What is data application octet stream?

The application/octet-stream MIME type is used for unknown binary files. It preserves the file contents, but requires the receiver to determine file type, for example, from the filename extension. The Internet media type for an arbitrary byte stream is application/octet-stream .

What is a multipart form data?

Multipart form data: The ENCTYPE attribute of <form> tag specifies the method of encoding for the form data. It is one of the two ways of encoding the HTML form. It is specifically used when file uploading is required in HTML form. It sends the form data to server in multiple parts because of large size of file.

Should I use multipart form data?

Multipart/form-data should be used for submitting forms that contain large files, non-ASCII data, and large binary data. Moreover, multipart/form-data can be used for forms that are presented using representations like spreadsheets, Portable Document Format, etc. i.e other than HTML.

Is multipart form data restful?

Multipart/Form-Data is a popular format for REST APIs, since it can represent each key-value pair as a “part” with its own content type and disposition. Each part is separated by a specific boundary string, and we don't explicitly need Percent Encoding for their values.


1 Answers

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.

like image 142
Stefan Kögl Avatar answered Sep 19 '22 19:09

Stefan Kögl