If you have metadata that you want to send along with the data to upload, you can make a single multipart/related request. This is a good choice if the data you are sending is small enough to upload again in its entirety if the connection fails.
To use multipart upload, make a POST or PUT request to the upload method's URI and add the query parameter uploadType=multipart.
The top-level HTTP headers to use when making a multipart upload request include:
Content-Type. Set to multipart/related and include the boundary string you're using to identify the parts of the request.Content-Length. Set to the total number of bytes in the request body.The body of the request is formatted as a multipart/related content type [RFC2387] and contains exactly two parts. The parts are identified by a boundary string, and the final boundary string is followed by two hyphens.
Each part of the multipart request needs an additional Content-Type header:
The following example shows the use of a multipart upload request for an upload path that would be /upload:
POST /upload?uploadType=multipart HTTP/1.1
Host: www.example.com
Content-Type: multipart/related; boundary="foo_bar_baz"
Content-Length: number_of_bytes_in_entire_request_body
--foo_bar_baz
Content-Type: application/json; charset=UTF-8
{
"name": "Some value"
}
--foo_bar_baz
Content-Type: image/jpeg
JPEG data
--foo_bar_baz--
If the request succeeds, the server returns the HTTP 200 OK status code along with any metadata:
HTTP/1.1 200
Content-Type: application/json
{
"name": "Some value"
}