Skip to content

Instantly share code, notes, and snippets.

@slavic18
Created March 8, 2017 12:54
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 slavic18/8880b7de8320f73c58d4a25bde8eb9a5 to your computer and use it in GitHub Desktop.
Save slavic18/8880b7de8320f73c58d4a25bde8eb9a5 to your computer and use it in GitHub Desktop.
node Multer configuration for saving files with extensions
var path = require('path');
var path = require('crypto');
var multer = require('multer');
var storage = multer.diskStorage({
destination: './uploads/',
filename: function (req, file, cb) {
crypto.pseudoRandomBytes(16, function (err, raw) {
if (err) return cb(err)
cb(null, raw.toString('hex') + path.extname(file.originalname))
})
}
});
var upload = multer({ storage: storage })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment