Difference between revisions of "REST API:Multipart Request"

From AgileApps Support Wiki
imported>Aeric
 
imported>Aeric
 
(2 intermediate revisions by the same user not shown)
Line 6: Line 6:


--.............................103832778631715
--.............................103832778631715
Content-Disposition: form-data; name="xml_part1;
Content-Disposition: form-data; name="__xml_part__";
Content-Type: application/xml;
Content-Type: application/xml;


Line 24: Line 24:
:*The Content-type of the request is set to <tt>multipart/form-data</tt> with an appropriate boundary.  
:*The Content-type of the request is set to <tt>multipart/form-data</tt> with an appropriate boundary.  


:*The first part contains the information portion of request, with Content-type set to <tt>application/xml</tt> or <tt>application/json</tt>, as appropriate. (The names and attributes of the different parts will vary, depending on the API.)
:*The first part contains the information portion of request, with Content-type set to <tt>application/xml</tt> or <tt>application/json</tt>, as appropriate. The name of the part is either <tt>__xml_part__</tt> or <tt>__json_data__</tt>.


:*The next part of the request is the actual file. The filename attribute for this part is the name of the file that is being uploaded. Here, the Content-type is <tt>application/octet-stream</tt>.  
:*The next part of the request is the actual file. The filename attribute for this part is the name of the file that is being uploaded. Here, the Content-type is <tt>application/octet-stream</tt>.  

Latest revision as of 00:34, 25 May 2012

A multipart request lets you send a package of data that includes the typical XML or JSON request accompanied by other data (typically, the contents of a file).

Here's a sample request:

Content-Type: multipart/form-data; boundary=.............................103832778631715

--.............................103832778631715
Content-Disposition: form-data; name="__xml_part__";
Content-Type: application/xml;

<platform>
    {the XML portion of the request}
</platform>

.............................103832778631715
Content-Disposition: form-data; name="file_part"; filename="someImage.jpg"
Content-type: application/octet-stream

{contents of the file}
.............................103832778631715--
Considerations
  • The Content-type of the request is set to multipart/form-data with an appropriate boundary.
  • The first part contains the information portion of request, with Content-type set to application/xml or application/json, as appropriate. The name of the part is either __xml_part__ or __json_data__.
  • The next part of the request is the actual file. The filename attribute for this part is the name of the file that is being uploaded. Here, the Content-type is application/octet-stream.
  • To send binary data over the wire, it must first be encoded. But for a CSV file, for example, the Content-type could be text/plain.