I'm using multer to upload a file. It's uploading fine but I can't work out how to get the generated filename it's made. I'd like to post it back into the response. The filename that's been made is highlighted in the comments:
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, '../app/src/assets/game/src/assets/images/')
},
filename: function (req, file, cb) {
cb(null, file.fieldname + '-' + Date.now() + '.png') <!-- I need this in my postback response -->
}
});
const upload = multer({ storage: storage }).single('avatar');
router.post('/upload/', function (req, res) {
upload(req, res, function (err) {
if (err) {
// An error occurred when uploading
throw err;
}
res.json({
sucess: true,
message: 'Image was uploaded successfully'
});
// Everything went fine
})
});