Created
October 2, 2016 17:36
-
-
Save CapeRatel/3f50d58ea9490b327ea75d678692f127 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| uploadAvatar: function (req, res) { | |
| req.file('avatar').upload({ | |
| // don't allow the total upload size to exceed ~10MB | |
| maxBytes: 10000000 | |
| },function whenDone(err, uploadedFiles) { | |
| if (err) { | |
| return res.negotiate(err); | |
| } | |
| // If no files were uploaded, respond with an error. | |
| if (uploadedFiles.length === 0){ | |
| return res.badRequest('No file was uploaded'); | |
| } | |
| // Save the "fd" and the url where the avatar for a user can be accessed | |
| User.update(req.session.me, { | |
| // Generate a unique URL where the avatar can be downloaded. | |
| avatarUrl: require('util').format('%s/user/avatar/%s', sails.getBaseUrl(), req.session.me), | |
| // Grab the first file and use it's `fd` (file descriptor) | |
| avatarFd: uploadedFiles[0].fd | |
| }) | |
| .exec(function (err){ | |
| if (err) return res.negotiate(err); | |
| return res.ok(); | |
| }); | |
| }); | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment