File Upload
In OpenAPI 3.0, you can describe files uploaded directly with the request content and files uploaded with multipart requests. Use the requestBody keyword to describe the request payload containing a file. Under content, specify the request media type (such as image/png or application/octet-stream). Files use a type: string schema with format: binary or format: base64, depending on how the file contents will be encoded. For example:
requestBody:
content:
image/png:
schema:
type: string
format: binaryThis definition corresponds to an HTTP request that looks as follows:
POST /upload
Host: example.com
Content-Length: 808
Content-Type: image/png
[file content goes there]Upload via Multipart Requests
To describe a file sent with other data, use the multipart media type. For example:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
orderId:
type: integer
userId:
type: integer
fileName:
type: string
format: binaryThe corresponding HTTP request payload will include multiple parts:
Multiple File Upload
Use the multipart media type to define uploading an arbitrary number of files (an array of files):
The corresponding HTTP request will look as follows:
References
For more information about file upload in OpenAPI, see the following sections of the OpenAPI 3.0 Specification:
Last updated