-
Notifications
You must be signed in to change notification settings - Fork 585
Someone can post an example of how implement file upload on a controller #265
Comments
Based on your output, it looks like you did receive the file. Have you attempted to just access the file via file.path or the file data via file.buffer? |
Hi Scott, What I've finishing doing is:
I don't want this middleware to be applied for all the routes, so reformulating my question is : How add PRE and/or POST middleware to swagger per routes? I read some similar and say that "...is handled by #209" If you can provide an example it would be great. |
If you're trying to tell me what you're trying to do, I am sure I can whip up an example or at least point you in the right direction. |
Also, it seems you're using multiple different versions of |
Hi Jeremy, Yes you are right, in fact in this moment I was reading why all the extra effort? what was wrong with using the file produced by multer via req.swagger.params.file.value? Well then. If another insomniac like mine, would fall in the same thing:
Quoting Jeremy by the way: Sorry, I have a couple of days with swagger and my starting point was @whitlockjc , @theganyo – guys thank you very much. |
I'm glad you got it sorted. |
I will likely update multer in swagger-tools' next release but it should work fine as-is. If the current version is causing you issues, let us know. As for your solution, that is how I would handle it, using the file buffer to write to where I needed. I do know with multer you can specify the upload location but that seems to be very implementation specific so I took a more general approach. |
Yes I agree with you. For now I'm saving files locally but indeed using this approach (buffer or stream) is better and when needed to switch to a cloud storage the impact on code changes and performance will be meaningless. |
Hi! I'm using swagger request validation tool and multer, but after using swagger validate req I already have req.files fulfilled and my multer does not handle anything. When I don't use swawgger validation all works fine. How can I solve this problem? |
@MaksymRadko what swagger request validation tool? |
@oliverhr your comments helped me a lot, thanks mate! |
Your are welcome @robertoclavijob, Im glad to hear that. |
Hi everyone, If I don't use swagger and just call my controller, I can't find the metadata parameter. Can anyone please explain what I am doing wrong. I use swagger-tools: 0.10.4, swagger-ui-express:2.0.15, multer-gridfs-storage:3.3.0, multer: 1.4.2 Here is my swagger spec params :
//My app.js snippets using swagger middleware swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
}); //my controller const crypto = require('crypto'); async function uploadFile(req,res,next){
} Can any one help as to what's going on? Have been stuck for more than a week now. |
@MaksymRadko were you able to solve the problem |
@whitlockjc @theganyo @oliverhr Thank you so much, the above comments helped me a lot! |
Hi @rodriguesnavil good to hear, I don't use anymore this library (I leave the project where I use it), seems a little bit unmaintained, don't know if there are more new alternatives, but if you need help with this ping me, I don't promise to know all the answers but if I can help you I'll do :) |
Thank you for your kind words, I'll surely ping you if I get stuck somewhere :) |
Please help!
I tried with fs and multer, but I could not make it work.
Note: Is an express project and was generated using swagger-project (last version).
My Debug output
thank you in advance.
The text was updated successfully, but these errors were encountered: