I have to upload multiple-files (already done), but each of them have to have a specific name (1.jpg, 2.jpg, 3.jpg etc). I've tried something like this, but the problem is that I can't change the file name, the files keep their original names
app.post('/upload', uploadMiddleware, (req, res) => {
const files = req.files;
files.forEach((file) => {
const filePath = `uploads/${file.filename}`;
fs.rename(file.path, filePath, (err) => {
if (err) {
// Handle error appropriately and send an error response
return res.status(500).json({ error: 'Failed to store the file' });
}
});
})
res.redirect('/gameCustom')
});