html - separate file uploads node.js -


i want know easiest way handle 2 separate file uploads, 1 images , other audio. right using multer , uploads multipart uploads same location. can specify different locations both file uploads?

assuming want save files disk, can this:

var storage = multer.diskstorage({     destination: function(req, file, cb) {         if (file.fieldname === 'image-file') {             return cb(null, 'folder-for-image-uploads');         }          if (file.fieldname === 'audio-file') {             return cb(null, 'folder-for-audio-uploads');         }          cb(new error('unknown fieldname: ' + file.fieldname));     },     filename: function(req, file, cb) {         if (file.fieldname === 'image-file') {             return cb(null, 'image-filename.jpg');         }          if (file.fieldname === 'audio-file') {             return cb(null, 'audio-filename.mp3');         }          cb(new error('unknown fieldname: ' + file.fieldname));     } });  var upload = multer({storage: storage});  app.post('/endpoint', upload.fields([{name: 'image-file', maxcount: 1}, {name: 'audio-file', maxcount: 1}]), function(req, res) {     // handle request, files saved disk     res.sendstatus(200); } 

for work, need name of input html elements match fieldname property, e.g.:

<form method="post" action="/endpoint" enctype="multipart/form-data">     <input type="file" name="image-file">     <input type="file" name="audio-file">     <input type="submit">submit</input> </form> 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -