Last active
December 10, 2015 22:29
-
-
Save enyo/4502571 to your computer and use it in GitHub Desktop.
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 path = require("path"); | |
exports.media = function(req, res, next) { | |
var file = req.files.media_upload; | |
// code to handle file here: | |
// file should already be in the right location | |
// The path, this file has been saved at should be: | |
file.path; | |
// To get only the filename of this path: | |
var filename = path.basename(file.path); | |
Project.findById(req.params.id, function(err, project) { | |
// First make sure that media is actually an array, not undefined. | |
if (!project.media) { project.media = [ ]; } | |
// Now add the filename | |
project.media.push(filename); | |
// And save it | |
project.save(function(err) { | |
if (err) { return next(err); } | |
res.send("success"); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment