zahraei
zahraei

Reputation: 79

Not recognizing the pdf file multer node js

const multer=require('multer');

var fileStorage = multer.diskStorage({

destination:(req,file,cb)=>{
    if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/jpg' || file.mimetype==='image/png') {

        cb(null, 'images')
    } 
    else if (file.mimetype === 'file/pdf') {
        cb(null, 'files')
    } 
    else {
        console.log(file.mimetype)
        cb({ error: 'Mime type not supported' })
    }
},

filename:(req,file,cb)=>{
    cb(null,Math.floor(Math.random()*10000000000) +'-'+ file.originalname);
}

var upload = multer({storage:fileStorage});

router.post('/UploadFile',upload.single('file'),Usercnl.UploadFile)

I want to save files with different extensions in different paths.

But it does not recognize the pdf file

Upvotes: 0

Views: 3189

Answers (1)

Timmy
Timmy

Reputation: 101

I had to change file to application in order to wrok. Hopes this helps:

file.mimetype === 'application/pdf'

Upvotes: 4

Related Questions