File upload not working
See original GitHub issueHello,
I have an endpoint documented like this:
post.apiDoc = {
description: 'Upload an image for the category',
operationId: 'uploadCategoryImage',
tags: ['categories'],
consumes: ['multipart/form-data'],
parameters: [
{
name: 'image',
in: 'formData',
type: 'file',
description: 'An image for this category',
required: true
}
],
responses: {
201: {
description: 'Image successfully uploaded'
},
default: {
description: 'Unexpected error',
schema: {
$ref: '#/definitions/Error'
}
}
}
};
In the Swagger UI, a file upload thing is visible:
However, I keep getting this error when I send a file:
{
path: 'image',
errorCode: 'required.openapi.validation',
message: 'instance requires property "image"',
location: 'body'
}
I do have a Content-Type: multipart/form-data
header in the HTTP request.
Am I doing something wrong or is it a bug?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:16 (15 by maintainers)
Top Results From Across the Web
File Upload not working, how do i fix this? - Microsoft Community
1) Reset the browsers in Windows Settings > Apps & Features > Browser > Advanced Options > Reset and Repair to see if...
Read more >forms - File upload not working | Php - Stack Overflow
As soon as I use enctype="multipart/form-data", nothing works at all the page simply refreshes. But, when I'm not using enctype="multipart/form ...
Read more >I Can't Upload My Files - Strikingly Help Center
I Can't Upload My Files · Step 1: Check your file · Step 2: Exit the editor and try again · Step 3:...
Read more >How to Solve File Upload Errors in Google Drive - MakeUseOf
How to Solve File Upload Errors in Google Drive: 8 Quick Solutions · 1. Check Google Drive's Status · 2. Check Your Network...
Read more >Troubleshooting file upload problems - UK Copyright Service
Make sure the file is not corrupted. · Copy the file to your home/desktop folder and upload from there. · Don't upload folders...
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
I got it to work with
multer
and a little tweak. Hopefully the following examples will be helpful for some people.Multer is a multipart form-data handling middleware. by default it stores the upload to
req.file
orreq.files
. The express-openapi-validation logic is looking for defined files inreq.body
. So we need to copy the file upload to the expected position.@hkors there’s currently no support for file uploads. It would be great if you could propose a solution. Most swagger frameworks that I’ve seen don’t handle this very well. I’d love
express-openapi
to be one of the first!