Answer the question
In order to leave comments, you need to log in
Multer not adding file to folder?
Good day to all!
The problem is this: the multer library, which serves as a middleware for adding files, does not add pictures to the specified folder.
I created a new node.js project and I'm trying to use multer, the configuration is set up correctly, there are no errors, but when sending a picture via Postman to the folder, they are not added, I don't understand what the problem could be, I'll be glad for any ideas. Thank you!
Server file:
const express = require('express');
const upload = require('./middleware/upload');
const app = express();
app.listen(5000, () => {
console.log('App has been started!')
});
app.post('/api/addPic', upload.single('image'), async (req, res) => {
res.send('All ok!')
});
const multer = require('multer');
const moment = require('moment');
const storage = multer.diskStorage({
destination(req, file, callback) {
callback(null, 'up/');
},
filename(req, file, callback) {
const date = moment().format('DDMMYYYY-HHmmss SSS');
callback(null, `${date}-${file.originalname}`);
}
});
module.exports = multer({
storage: storage,
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question