From 1404cf9328cdc07daeb00f791b555b686de23742 Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Sun, 3 Jul 2022 10:18:04 +0700 Subject: [PATCH] fix: utf-8 filename breaks https://github.com/expressjs/multer/issues/1104 --- controllers/uploadController.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 64128448a..57965fcd7 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -110,12 +110,16 @@ const executeMulter = multer({ files: maxFilesPerUpload }, fileFilter (req, file, cb) { + // BUG: Since multer@1.4.5-lts.1, UTF-8 filenames are not handled properly, so we force it + file.originalname = file.originalname && + Buffer.from(file.originalname, 'latin1').toString('utf8') + file.extname = utils.extname(file.originalname) if (self.isExtensionFiltered(file.extname)) { return cb(new ClientError(`${file.extname ? `${file.extname.substr(1).toUpperCase()} files` : 'Files with no extension'} are not permitted.`)) } - // Re-map Dropzone keys so people can manually use the API without prepending 'dz' + // Re-map Dropzone chunked uploads keys so people can manually use the API without prepending 'dz' for (const key in req.body) { if (!/^dz/.test(key)) continue req.body[key.replace(/^dz/, '')] = req.body[key]