I created an Express app in combination with multer to upload items in my Node.js app
What I try to do is select let's say:
Upload 1 - that has a fieldname of upfile1
Upload 2 - that has a fieldname of upfile2
Upload 3 - that has a fieldname of upfile3
basically, I need to select every uploaded filename item of my multi-upload app separately. Every upload needs to be handled differently in the app for different tasks. Let's use console.log as an example I need to do something like:
console.log(req.body.upfile1.filename);
console.log(req.body.upfile2.filename);
console.log(req.body.upfile3.filename);
to select the different items that get's handled in the app using different fieldname that are defined in my views using the name attribute.
below is my code
Views [index.html]
<form id="app-form" method="POST" class="fileupload" method="post" action="app" enctype="multipart/form-data">
<h1>Multi File Uploads</h1>
<input type="file" name="upfile1" value="">
<input type="file" name="upfile2" value="">
<input type="file" name="upfile3" value="">
<input type="submit" />
</form>
NodeJS [app.js]
app.get("/", function(req, res) {
res.sendFile(__dirname + "/index.html");
});
app.post("/app", upload.any(), function(req, res) {
let files = req.files;
files.forEach(file => {
console.log(file.filename);
});
res.send(req.files);
res.end();
});
Help would be very appreciated, thanks!