multer icon indicating copy to clipboard operation
multer copied to clipboard

expose filename*

Open bejito opened this issue 4 years ago • 7 comments

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 ?

bejito avatar Oct 15 '19 09:10 bejito

Actually, originalname seems to read it, but the value it exposes just contains bunch of � for non ascii charactes

bejito avatar Oct 15 '19 09:10 bejito

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!

jonchurch avatar Jan 15 '20 23:01 jonchurch

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

ryhinchey avatar Apr 11 '20 02:04 ryhinchey

After some debugging, the problem is in Busboy:

image

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:

image

hope it helps!

erano067 avatar May 17 '22 21:05 erano067

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.

erano067 avatar May 17 '22 22:05 erano067

I created a PR #1092 to bump up busboy version, please approve

erano067 avatar May 17 '22 23:05 erano067

Version 1.4.4-lts.1 is released with the latest version of Busboy. Does this solve this problem?

LinusU avatar May 29 '22 10:05 LinusU