Skip to main content

File upload

OpenAPI 3.0 provides two ways to upload files:

File upload via request body

File would be uploaded via request body. The request body should be of type string and format binary.

openapi: 3.0.3
info:
title: Example
version: 1.0.0
paths:
/avatar:
post:
summary: Upload avatar
operationId: uploadAvatar
requestBody:
required: true
content:
image/png:
schema:
type: string
format: binary
responses:
'200':
description: OK

File upload via multipart request

Multiple files can be uploaded via multipart request, along with other fields.

openapi: 3.0.3
info:
title: Example
version: 1.0.0
paths:
/post:
post:
summary: Creates new post
operationId: newPost
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
required: [ title, content ]
properties:
title:
type: string
content:
type: string
thumbnail:
type: string
format: binary
attachments:
type: array
items:
type: string
format: binary
responses:
'200':
description: OK