-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Wrong encoding in originalname containing unicode characters #962
Comments
Version : 1.4.2 Same with your problem. I am using Postman to upload a file with Chinese name,
and file.originalname gives me some garbled code (such as Л�bentley�revit!�-@r7.rvt).
|
It's Postman's problem not multer. You can always get correct originalname with curl or axios. For example: curl --location --request POST 'http://localhost:8080/files' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6Ik...' \
--form 'files=@"/Users/keliq/Pictures/截图/小白菜.jpeg"' |
You may need this: req.files[0].originalname = Buffer.from(req.files[0].originalname, 'latin1').toString('utf-8'); |
you can try update multer package from 1.4.2 to ^1.4.5-lts.1, i successed at 2023.3.14 |
@ElderlyBoy I saw a lot of people just adding this line and they say just add it to multer configuration, can you please tell me exactly where should I add it as I'm fairly new to this? |
@MohamedClio //example
router.post('/example', (req, res) => {
req.files[0].originalname = Buffer.from(req.files[0].originalname, 'latin1').toString('utf-8');
//...your code
}) |
Just a note: This code above assumes that |
It's not entirely correct - multer by default decodes headers values as This PR #1210 provides you a straightforward way to encode the headers as you expect them to be |
multer uses busboy and if I understand the busboy code correct it more or less supports latin1, utf8 and utf16. But there are dozens of other encodings. https://github.com/mscdex/busboy/blob/master/lib/utils.js#L384 |
Multer has a bug, so it uses busboy incorrectly |
Version : 1.4.2
System : Windows 10
When uploading a file whose name contains unicode character, file.orginalname turns out to be some messy code, indicating something has gone wrong in encoding.
Maybe the problem isn't with multer, but I cannot find a way to get the encoding proper. Any explanation or solution will be appreciated ❤️
The text was updated successfully, but these errors were encountered: