express-openapi-validator
express-openapi-validator copied to clipboard
question: file upload using axios and validator
Using the following route specification:
/user/avatar:
patch:
operationId: patchUserAvatar
summary: Upload user avatar
description: Upload a user avatar
tags:
- Users
requestBody:
description: Avatar image
required: true
content:
multipart/form-data:
schema:
type: object
properties:
avatar:
type: string
format: binary
description: Avatar image
required:
- avatar
I'm trying to upload an image from the frontend using axios as followed:
const payload = new FormData()
payload.append('avatar', image)
axios.patch(`/user/avatar`, payload, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
Where image has the structure:
{
name: ...,
type: ...,
uri: ....,
}
and represents a file on disk.
However express-openapi-validator returns the following error:
{
"errors": [{
"message":"multipart file(s) required","path":"/user/avatar"
}],
"name":"Bad Request",
"status":400
}
Given the error it's not entirely clear what is going wrong. The header is set to multipart and the form attaches one file. Can anyone see what is going wrong here?