A
A
AndeDark2021-03-03 23:02:35
Express.js
AndeDark, 2021-03-03 23:02:35

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!')
});


multer config file:
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,
});


Sending a picture via Postman
603feae1e2511241681375.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question