node.js - How to store a file with file extension with multer? -


managed store files in folder store without file extension.

does 1 know how store file file extension?

from docs: "multer not append file extension you, function should return filename complete file extension."

here's how can add extension:

var multer = require('multer');  var storage = multer.diskstorage({   destination: function (req, file, cb) {     cb(null, 'uploads/')   },   filename: function (req, file, cb) {     cb(null, date.now() + '.jpg') //appending .jpg   } })  var upload = multer({ storage: storage }); 

i recommend using mimetype property determine extension. example:

filename: function (req, file, cb) {   console.log(file.mimetype); //will return like: image/jpeg 

more info: https://github.com/expressjs/multer


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -