Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can I upload image or json file ? #1221

Open
SheikhElMoctarG opened this issue Jul 20, 2023 · 1 comment
Open

how can I upload image or json file ? #1221

SheikhElMoctarG opened this issue Jul 20, 2023 · 1 comment

Comments

@SheikhElMoctarG
Copy link

when I tried to upload json file, I found this error:
MulterError: Unexpected field at wrappedFileFilter (E:\nodejs-projects\uploadFiles\node_modules\multer\index.js:40:19) at Multipart.<anonymous> (E:\nodejs-projects\uploadFiles\node_modules\multer\lib\make-middleware.js:107:7) at Multipart.emit (node:events:513:28) at HeaderParser.cb (E:\nodejs-projects\uploadFiles\node_modules\busboy\lib\types\multipart.js:358:14) at HeaderParser.push (E:\nodejs-projects\uploadFiles\node_modules\busboy\lib\types\multipart.js:162:20)

how can I upload json file and add extension of file ? what abou Xlsx files ?

@Sameercode660
Copy link

Hello, SheikhEIMoctarG, for uploading the specific type of data , you have to configure the multer explicitly
const upload = multer({
storage: storage,
fileFilter: function (req, file, cb) {
// Allow only JSON and Xlsx files
if (file.mimetype === 'application/json' || file.mimetype === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
cb(null, true);
} else {
cb(new Error('Unsupported file type'), false);
}
},
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants