简体   繁体   中英

file upload mime type issue with Multer Node.js

in my project, I got to upload a Photoshop file with Multer but when I put the mime type of photoshop, wave, and mp3 files I got this error:

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)

this is my code:

 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 ]);
can you please help me to resolve this problem

Try to chage file/psd to some of this (the first one should work):

image/vnd.adobe.photoshop

application/x-photoshop

application/photoshop

application/psd

image/psd

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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