无法识别pdf文件multer节点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,cb)=>{
    cb(null,Math.floor(Math.random()*10000000000) +'-'+ file.originalname);
}

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

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

我想将具有不同扩展名的文件保存在不同的路径中。

但是它无法识别pdf文件

microwebhk 回答:无法识别pdf文件multer节点js

我不得不将文件更改为应用程序才能运行。希望这会有所帮助:

file.mimetype === 'application/pdf'
本文链接:https://www.f2er.com/3119103.html

大家都在问