How can I accept files from several file type fields?
I have the following code that uploads a single file using multer in node.js:
var storage = multer.diskStorage({ destination: function (req, file, callback) { callback(null, './public/uploads'); }, filename: function (req, file, callback) { callback(null, file.fieldname + '-' + Date.now()); } }); var upload = multer({ storage : storage }); app.post('/rest/upload', upload.array('video', 1), function(req, res, next){ ... }
From the following form, provided that only the video field matters (if I specify how I get the "Unexpected field" error):
<form action="/rest/upload" method="post" enctype="multipart/form-data"> <label>Video file: </label> <input type="file" name="video"/> <label>Subtitles file: </label> <input type="file" name="subtitles"/> <input type="submit"/> </form>
From the documentation it is not clear how to approach this? We appreciate any suggestions. BTW I tried the following options for options, without success:
app.post('/rest/upload', [upload.array('video', 1), upload.array('subtitles', 1)] ... app.post('/rest/upload', upload.array('video', 1), upload.array('subtitles', 1), ... app.post('/rest/upload', upload.array(['video', 'subtitles'], 1), ...