Edit Page
Uploading to Mongo GridFS
Uploading files to MongoDB is possible thanks to Mongo's GridFS filesystem. With Sails, you can accomplish this with very little additional configuration using the Skipper adapter for MongoDB's GridFS.
Install it with:
$ npm install skipper-gridfs --save
Then use it in one of your controllers:
uploadFile: function (req, res) {
req.file('avatar').upload({
adapter: require('skipper-gridfs'),
uri: 'mongodb://[username:[email protected]]host1[:port1][/[database[.bucket]]'
}, function (err, filesUploaded) {
if (err) return res.negotiate(err);
return res.ok();
});
}
Is something missing?
If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.