-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File upload not working #29
Comments
I can now receive the file by adding |
@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 |
Hi! The issue should be fixed now, I had the same problem. |
@hkors if you're able to try again with the latest version it would be appreciated. I'll leave this issue open until we have confirmation that file uploads work. |
Actually the bug is still present. |
kogosoftwarellc/express-openapi-validation@0096f84 |
@mghignet sorry for the late reply. Holidays and election happened here in the states. Barely getting back in the swing of things. Whatever we need to do to get file uploads working, as long as the tests pass, I say we do it! Can you submit a PR? |
I got it to work with Multer is a multipart form-data handling middleware. by default it stores the upload to expressOpenapi.initialize({
consumesMiddleware: {
// example 1: Allow for single file upload (filename: 'file')
'multipart/form-data'(req, res, next) {
multer().single('file')(req, res, (err) => {
if (err) return next(err);
req.body.file = req.file;
next();
});
}
// example 2: Allow for any file upload
'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);
next();
});
}
},
}); |
Nice @alrik ! Can you by chance update the README with this example, and possibly create a test (i.e. can you add |
Hey @jsdevel sure. I'll add an example to the readme and add some tests when i got some spare time. Could you assign me the issue, so that i don't forget about it? |
@alrik looks like I'm unable to assign to non-project collaborators. If you own an issue, I can assign it to you. Want to open a new issue here about a missing example in the README for file uploads? I should be able to assign that to you. |
I submit that this issue is addressed satisfactorily by #105 |
Agreed. Thanks @simpgeek! @hkors let us know if you disagree. |
i'm getting an error trying to test this with curl. The spec is:
and express-openapi is initialised as suggested:
Hitting the app with curl:
The same happens with superagent/supertest and postman. Any hints? |
@mbsimonovic please file a new issue. that appears to be related to V3 which wasn't published at the time this issue was created. |
Hello,
I have an endpoint documented like this:
In the Swagger UI, a file upload thing is visible:
However, I keep getting this error when I send a file:
I do have a
Content-Type: multipart/form-data
header in the HTTP request.Am I doing something wrong or is it a bug?
The text was updated successfully, but these errors were encountered: