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
Post a Comment