Last active
October 30, 2018 20:23
-
-
Save rwclarke/8f82e83198eaaa8f7473 to your computer and use it in GitHub Desktop.
Sails js v0.10 Uploading image to Cloudinary (Image Management)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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