express-openapi-validator icon indicating copy to clipboard operation
express-openapi-validator copied to clipboard

unsupported media type

Open tamis-laan opened this issue 3 years ago • 0 comments

I'm trying to upload a file but I'm not sure what is going wrong here. Looks like an openapi validation error. Maybe someone can help me out?

Client side (nodejs with form-data):

let buffer = fs.readFileSync('./image');
var form = new FormData();
form.append('file', buffer)
const result = await this.axios.patch(`/test`, 
  form.getBuffer(), 
  form.getHeaders()
)

Server side (express openapi validator)

/test
  requestBody:
    content:
      multipart/form-data:
        schema:
          type: object
          properties:
            file:
              type: string
              format: binary
        encoding:
          flyer:
            contentType: image/*

This returns the error:

http: unsupported media type application/x-www-form-urlencoded {
  "errors":[{
    "message":"unsupported media type application/x-www-form-urlencoded",
    "path":"/test"
  }],
  "name":"Unsupported Media Type",
  "status":415
}

If I print the form data headers form.getHeaders() I get the following:

headers {
  'content-type': 'multipart/form-data; boundary=--------------------------184468827363049933865303'
}

tamis-laan avatar Jan 08 '22 21:01 tamis-laan