fails to handle 'multipart/form-data' in openapi v3 (Unsupported Content-Type multipart/form-data; boundary=...)
See original GitHub issuei’m getting an error trying to handle file uploads with v3.6.0. The spec is:
openapi: "3.0.0"
servers:
- url: http://localhost:3000
description: local server
paths:
/upload/:
post:
summary: Create NEW files
operationId: upload
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
docs:
type: array
items:
type: string
format: binary
# tried this as well but also doesnt work:
# schema:
# type: object
# properties:
# upload:
# type: string
# format: binary
express-openapi is initialised as suggested:
'multipart/form-data'(req, res, next) {
multer().any()(req, res, (err) => {
if (err) return next(err);
req.files.forEach(f => req.body[f.fieldname] = f);
return next(); // this executes correctly
});
}
Hitting the app with curl or swagger-ui:
curl "http://localhost:3000/upload/" -H "accept: */*" -H "Content-Type: multipart/form-data" -F docs=@package.json
fails with the following error (the endpoint never gets called):
Unsupported Content-Type multipart/form-data; boundary=----WebKitFormBoundaryWyK9kAU7d35AKf26
The same happens with superagent/supertest and postman. Any hints?
Issue Analytics
- State:
- Created 5 years ago
- Comments:37 (37 by maintainers)
Top Results From Across the Web
The request was rejected because no multipart boundary was ...
In postman content-type="multipart/form-data" and I am getting the below exception. HTTP Status 500 - Request processing failed; nested exception is org.
Read more >Multipart Requests - Swagger
OAS 3 This guide is for OpenAPI 3.0. Multipart Requests. Multipart requests combine one or more sets of data into a single body,...
Read more >OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
It is common to use multipart/form-data as a Content-Type when transferring request bodies to operations. In contrast to 2.0, a schema is ...
Read more >Multipart (Form Data) Format - MuleSoft Documentation
shows a raw multipart/form-data payload with a 34b21 boundary consisting of 3 parts: a text/plain one named text. an application/json file ( a....
Read more >415 Unsupported Media Type - HTTP - MDN Web Docs
The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @mbsimonovic .
In your example, changing the spec like so:
(Note the
required
property.)This causes the following error:
This, I believe, is the crux of our issue!
Edit, to explain further: The reason your spec is validating is because the
files
property is in fact not being validated, because it’s an optional property. From the validator’s point of view, that property doesn’t exist to validate. Making it a required field changes all that. Now you’ll need to putfiles
on thereq.body
beforex-express-openapi-additional-middleware
, i.e. viaargs.consumesMiddleware
. Once that’s done, you’ll get the same error I’ve been getting all along:here you go. so
npm install
first, thennpm run test
.openapi-multipart-demo.zip