Skip to content

Instantly share code, notes, and snippets.

@rwclarke
Last active October 30, 2018 20:23
Show Gist options
  • Save rwclarke/8f82e83198eaaa8f7473 to your computer and use it in GitHub Desktop.
Save rwclarke/8f82e83198eaaa8f7473 to your computer and use it in GitHub Desktop.
Sails js v0.10 Uploading image to Cloudinary (Image Management)
var cloudinary = require('cloudinary');
cloudinary.config({
cloud_name: '',
api_key: '',
api_secret: ''
});
module.exports = {
upload: function (req, res) {
req.file('image').upload(function (err, uploadedFiles) {
if (err) {
return res.send(500, err);
} else {
cloudinary.uploader.upload(uploadedFiles[0].fd, function(result) {
Images.update(req.param('id'), {imagePath: result.url}, function imageUpdated (err) {
if (err) {
console.log(err);
return res.redirect('/');
}
res.redirect('/image/upload/' + req.param('id'))
});
});
}
});
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment