Created
July 26, 2017 14:30
-
-
Save BumbuKhan/17bd0e06e8393a4381af936029a1e8f1 to your computer and use it in GitHub Desktop.
ExpressJS file upload
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 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 }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Read more here expressjs/multer#170