Skip to content

Instantly share code, notes, and snippets.

@BumbuKhan
Created July 26, 2017 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BumbuKhan/17bd0e06e8393a4381af936029a1e8f1 to your computer and use it in GitHub Desktop.
Save BumbuKhan/17bd0e06e8393a4381af936029a1e8f1 to your computer and use it in GitHub Desktop.
ExpressJS file upload
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './uploads/')
},
filename: function (req, file, cb) {
crypto.pseudoRandomBytes(16, function (err, raw) {
cb(null, raw.toString('hex') + Date.now() + '.' + mime.extension(file.mimetype));
});
}
});
var upload = multer({ storage: storage });
@BumbuKhan
Copy link
Author

Read more here expressjs/multer#170

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment