繁体   English   中英

Multer Node.js 的文件上传 MIME 类型问题

[英]file upload mime type issue with Multer Node.js

在我的项目中,我必须使用 Multer 上传一个 Photoshop 文件,但是当我输入 mime 类型的 photoshop、wave 和 mp3 文件时,我收到了这个错误:

Error: Mime type invalide
at DiskStorage.destination [as getDestination] (C:\Users\21653\Desktop\vagaBeats\back\src\midlleware\artworkImageUploader.js:14:21)
at DiskStorage._handleFile (C:\Users\21653\Desktop\vagaBeats\back\node_modules\multer\storage\disk.js:31:8)
at C:\Users\21653\Desktop\vagaBeats\back\node_modules\multer\lib\make-middleware.js:144:17
at allowAll (C:\Users\21653\Desktop\vagaBeats\back\node_modules\multer\index.js:8:3)
at wrappedFileFilter (C:\Users\21653\Desktop\vagaBeats\back\node_modules\multer\index.js:44:7)
at Busboy.<anonymous> (C:\Users\21653\Desktop\vagaBeats\back\node_modules\multer\lib\make-middleware.js:114:7)
at Busboy.emit (events.js:315:20)
at Busboy.emit (C:\Users\21653\Desktop\vagaBeats\back\node_modules\busboy\lib\main.js:38:33)
at PartStream.<anonymous> (C:\Users\21653\Desktop\vagaBeats\back\node_modules\busboy\lib\types\multipart.js:213:13)
at PartStream.emit (events.js:315:20)

这是我的代码:

 const multer = require("multer"); const path = require('path'); const MIME_TYPE_MAP = { "image/png": "png", "image/jpeg": "jpg", "image/jpg": "jpg", "file/psd": "psd" // i got a problem with this MIME TYPE }; const storage = multer.diskStorage({ destination: (req, file, cb) => { const isValid = MIME_TYPE_MAP[file.mimetype]; let error = new Error("Mime type invalide"); if (isValid) { error = null; } cb(error, path.join(__dirname, '../../', 'images/artworkImages')); }, filename: (req, file, cb) => { const name = file.originalname.toLowerCase().split(" ").join("-"); console.log(file) const ext = MIME_TYPE_MAP[file.mimetype]; cb(null, name + "-" + Date.now() + "." + ext); } }); module.exports = multer({ storage: storage }).fields([ { name: "Image"}, {name:"untagedartwork"}, {name:"psd_file"} //this is the file that i want to upload it to the server ]);
你能帮我解决这个问题吗

尝试将file/psd更改为其中的一些(第一个应该可以):

image/vnd.adobe.photoshop

application/x-photoshop

application/photoshop

application/psd

image/psd

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM