0

So, I have a simple controller with method upload:

upload: function (req, res) {
    req.file('fileName').upload(function (err, uploadedFile) {
        res.json({err: err, uploadedFile: uploadedFile});
    });
}

Everything works perfect, until I send file with which is not handled with req.file method. So for example if I send file with name 'someOtherFileName' and inside controller I expect 'fileName' skipper will hang and eventually (after like 2 minutes) break.

How can sails ignore files inside req that are not needed? Or at least, can I respond with error message like 'please use fileName as file param name'...

hlozancic
  • 1,489
  • 18
  • 31
  • I think you need to check it before your req.file().upload(). Something like `if(req.param.file != 'fileName') res.flash('Error')`. It's a good idea to use [Glob](https://github.com/isaacs/node-glob). Is that what you need? – Makah May 31 '16 at 23:40
  • Nope, skipper dies nevertheless... You can try it yourself on clean sails project. Whats interesting is that you don't need to handle upload at all... If you call ANY route and send file it will freeze... – hlozancic Jun 01 '16 at 06:39
  • I think first is a config `.upload({}, function (err, uploadedFile) { ... })` – Makah Jun 01 '16 at 13:52
  • It's not because of syntax... It's some problem with skipper default receiver... If you follow docs: http://sailsjs.org/documentation/concepts/file-uploads and use their example on CLEAN sails project you will get same problem... Infact just generate new project and call any route with file param and you will force timeout. – hlozancic Jun 01 '16 at 14:16
  • Struggled with this for a long time and then started writing tests so I can submit this as bug. Tests surprisingly uploaded everything as they should... So it seams like postman issue (was using postman to test upload route). If anyone wants to reproduce this do the following: sails new projectName | cd projectName | sails generate api something | sails lift | ... then open postman and make post request to localhost:1337/something/ with file inside request, and postman will halt. – hlozancic Jun 01 '16 at 18:41

0 Answers0