Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js:file upload using multer in sails.js

I would like to integrate multer https://www.npmjs.com/package/multer file upload package in my sails.js framework application unfortunately there is no tutorial avaliable for it.

Can anyone give a guidance how to do it in sails.js??

like image 931
Jabaa Avatar asked Oct 30 '22 05:10

Jabaa


1 Answers

I also came across this problem and wasn't able to find anything on internet but after reading sails.js documentations, I figured out a way to upload files.

Internally sails.js uses skipper to upload files and the code is pretty straightforward for it.

var uploadFile = req.file('user_picture');
uploadFile.upload({ dirname: filePath }, function onUploadComplete(err, files) {
  if (err) return res.serverError(err);
  //  IF ERROR Return and send 500 error
  console.log(files);
});

The user_picture is the name of the variable in your form.

Hope this helps!

like image 89
zenwraight Avatar answered Nov 15 '22 05:11

zenwraight