Sending image from react to multer

I’m trying to send image to multer(npm module),but its not throwing any error or saving the image … is this the right format of data to send to multer

if it is then is there issue in 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)=>{
            cb(null,'../upload/images')
        }, 
        filename:(req,file,cb)=>{
            const ext = MIME_TYPE_MAP[file.mimetype]
            cb(null,v1()+'.'+ext);
        }
    }),
    fileFilter: (req,file,cb)=>{
        const isValid = !!MIME_TYPE_MAP[file.mimetype];
        let error  = isValid ? null : new Error('INvalid mime type')
        cb(error,isValid);
    }
});

module.exports =fileUpload;

I haven’t used multer, but the code looks fine based on the examples. Is the file upload reaching the Node server you’re using multer on?

I added console logs the function is not getting triggered
but I added the middleware

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

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.