Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is http multipart request?

I have been writing iPhone applications for some time now, sending data to server, receiving data (via HTTP protocol), without thinking too much about it. Mostly I am theoretically familiar with process, but the part I am not so familiar is HTTP multipart request. I know its basic structure, but the core of it eludes me.

It seems that whenever I am sending something different than plain text (like photos, music), I have to use a multipart request. Can someone briefly explain to me why it is used and what are its advantages?

If I use it, why is it better way to send photos that way?

like image 518
MegaManX Avatar asked Jun 06 '13 09:06

MegaManX


People also ask

What is multipart HTTP request?

Multipart requests combine one or more sets of data into a single body, separated by boundaries. You typically use these requests for file uploads and for transferring data of several types in a single request (for example, a file along with a JSON object).

How does HTTP multipart work?

Multipart upload allows you to upload a single object as a set of parts. Each part is a contiguous portion of the object's data. You can upload these object parts independently and in any order. If transmission of any part fails, you can retransmit that part without affecting other parts.

What is multipart form data used for?

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.


2 Answers

An HTTP multipart request is an HTTP request that HTTP clients construct to send files and data over to an HTTP Server. It is commonly used by browsers and HTTP clients to upload files to the server.

  • What it looks like
  • See Multipart Content-Type
  • See multipart/form-data
like image 59
Iggy Avatar answered Oct 03 '22 09:10

Iggy


As the official specification says, "one or more different sets of data are combined in a single body". So when photos and music are handled as multipart messages as mentioned in the question, probably there is some plain text metadata associated as well, thus making the request containing different types of data (binary, text), which implies the usage of multipart.

like image 35
csonti Avatar answered Oct 03 '22 10:10

csonti