multar middleware not getting triggered

  express, javascript, middleware, multer, node.js

I’m trying to save image from react frontend to the backend but the images are not getting save,I added console logs in the multer code and I think the middleware is not getting triggered


router.post('/signup',fileUpload.single('image'),userController.signup)

multer code


const multer = require('multer')
const { v1: uuidv1, v1 } = require('uuid');

const MIME_TYPE_MAP = {
    'image/png':'png',
    'image/png':'jpeg',
    'image/png':'jpg',
};

const fileUpload = multer({
    limits:50000000,
    storage:multer.diskStorage({
        destination:(req,file,cb)=>{
            console.log(file)
            console.log('file')
            cb(null,'../upload/images')
        }, 
        filename:(req,file,cb)=>{
            console.log('file name')
            const ext = MIME_TYPE_MAP[file.mimetype]
            cb(null,v1()+'.'+ext);
        }
    }),
    fileFilter: (req,file,cb)=>{
        console.log('file filt')
        const isValid = !!MIME_TYPE_MAP[file.mimetype];
        let error  = isValid ? null : new Error('INvalid mime type')
        cb(error,isValid);
    }
});

module.exports =fileUpload;

Source: Ask Javascript Questions

LEAVE A COMMENT