MUST use multipart/form-data when combining data of several types in one body [91]
Multipart request 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) In OpenAPI 3, you describe a multipart request in the following way:
requestBody:
content:
multipart/form-data: # Media type
schema: # Request payload
type: object
properties: # Request parts
id: # Part 1 (string value)
type: string
format: uuid
address: # Part2 (object, for example image metadata)
type: object
properties:
street:
type: string
city:
type: string
profileImage: # Part 3 (an image)
type: string
format: binary
The example above corresponds to the following request:
POST /upload HTTP/1.1
Content-Length: 428
Content-Type: multipart/form-data; boundary=abcde12345
--abcde12345
Content-Disposition: form-data; name="id"
Content-Type: text/plain
123e4567-e89b-12d3-a456-426655440000
--abcde12345
Content-Disposition: form-data; name="address"
Content-Type: application/json
{
"street": "Blaak",
"city": "Rotterdam"
}
--abcde12345
Content-Disposition: form-data; name="profileImage "; filename="image1.png"
Content-Type: application/octet-stream
{…file content…}
--abcde12345--
MUST add Content-Disposition to the request header [92]
API consumer must add the Content-Disposition to the request header when calling the API. In case of a file, both the name and filename fields are mandatory.
MUST validate Content-Disposition name and filename are provided in the request header [93]
API provider must validate the existence of both the name and filename are provided in the request header.