Created
March 8, 2017 12:54
-
-
Save slavic18/8880b7de8320f73c58d4a25bde8eb9a5 to your computer and use it in GitHub Desktop.
node Multer configuration for saving files with extensions
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'); | |
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