IntroductionThe multipart post method is a different request body format for a POST method. The media-type multipart/form-data follows the rules of all multipart MIME data streams as outlined in RFC 1521. It is intended for use in returning the data that comes about from filling out a form, particularly when the form requires binary data to be uploaded such as the contents of a file. Typical UsageLike for the standard POST method, there are two main steps to using the multipart post method, setting the request data and retrieving the response data. The request data is specified by adding parameters to the method,
these are defined by the
Part SourcesThe The two concrete implementations of PartSource are FilePartSource and ByteArrayPartSource. FilePartSource simply takes a File to upload whereas ByteArrayPartSource allows for the case where the data has been cached in memory and takes a file name and a byte array to upload. Common ProblemsThe most common problem people run into with multipart uploads is that the length of the data must be known before hand. If the length of the data can not be determined in advance, it needs to be cached either in memory or to a file and then uploaded using either ByteArrayPartSource or FilePartSource. The HTTP specification does not allow for POST data to be of an unknown length. RFC SectionThe multipart form data uses the POST method from the HTTP standard which is defined in section 8.3 of RFC1945 and similarly redefined for HTTP 1.1 in section 9.5 of RFC2616 . The multipart/form-data MIME type used to format the body of the request is defined in RFC1867 . |