multer
multer copied to clipboard
expose filename*
In the Content-Disposition header spec, there is a field called filename*
that allows to stransmit utf8 characters.
Neither fieldname
not originalname
expose that field.
Is it possible to get the value in that field from the multer execution ?
Actually, originalname
seems to read it, but the value it exposes just contains bunch of � for non ascii charactes
Hmmm, this interesting.
Can you send a minimal reproduction of this issue? Specifically the non ascii character issue. Multer uses Busboy to deal with handling file uploads under the hood.
I'm not entirely sure if the originalname
field is messed with anywhere along the way that could reproduce this issue. But if you can send an example maybe we can step through it and find out what's happening.
Thanks!
This might have something to do with file encoding. See https://github.com/expressjs/multer/issues/434
https://github.com/expressjs/multer/pull/399 might solve this
After some debugging, the problem is in Busboy:
In my example the header of 'content-disposition'
is set to:
form-data; name="doc"; filename="××פס101.pdf"; filename*=UTF-8''%D7%98%D7%95%D7%A4%D7%A1101.pdf
making a double filename
fields.
Then in the for loop it takes the ugly first filename
and convert it to utf-8, in that stage the filename
variable looks good.
but then it makes another iteration and overwrite filename
with the result of this function:
filename = decodeText(parsed[i][1], 'binary', 'utf8');
when we call that function in the second time we send it a 'utf-8' string, and tells it to decode the text from source = 'binary' to target = 'utf-8'. And that makes the ugly � �question � � marks � �.
I will open an Issue in busboy and then we need to bump multer's busboy dependency.
for now as a workaround I managed to send the filename alongside the file itself like this:
hope it helps!
After some more investigation multer uses busboy version ^0.2.11 which gives 0.2.14.
as for now busboy have a 1.6.0 version and by the looks of it it seems busboy implements the filename*=UTF-8''...
feature of content-disposition
.
so to solve this issue we just need to migrate to higher version of busboy.
I created a PR #1092 to bump up busboy version, please approve
Version 1.4.4-lts.1
is released with the latest version of Busboy. Does this solve this problem?