multer icon indicating copy to clipboard operation
multer copied to clipboard

Cannot change encoding.

Open ghost opened this issue 8 years ago • 10 comments

I want to change the files encode or a way to tell multer to do that.. I followed the documentation that totally not working.. I searched for any clue inside the stroage class iteslf but with no luck.

Thanks in advance, sayeko.

ghost avatar Dec 22 '16 22:12 ghost

What encoding do you mean? The files are saved as they are received over the wire I think...

LinusU avatar Dec 23 '16 08:12 LinusU

I have files that contain hebrew or arabic language and when I saved it with multer I get white square with question marks instead of the text.. its an encoding issue that I can solve on the server side but I dont have an options with multer to change it.

ghost avatar Dec 23 '16 09:12 ghost

Any help?

ghost avatar Dec 28 '16 18:12 ghost

Did you ever resolve this? I myself tried to set encoding to ucs2 but that didn't resolve the issue.

occasl avatar Mar 13 '17 21:03 occasl

hello @occasl @sayeko , I have the same problem here, did you find a way out ?

po-jo avatar Jul 05 '18 14:07 po-jo

You can always fork multer and add your encoding functionality or after you upload your files change the encoding by your self in code and create new files from them with the correct encoding.

hope it help you.

ghost avatar Jul 07 '18 08:07 ghost

I'll need some more information before I can fix this. Could someone supply a wire dump of what gets sent to the server when uploading e.g. a file that contains Hebrew/Arabic language that is being saved incorrectly by Multer?

LinusU avatar Jul 07 '18 10:07 LinusU

hello @sayeko : yep, I have found a turnaroud after multer to re-encode/decode data by myself. hello @LinusU : I have a small Uint8Array with latin characters within easy hand, does that help ? [100, 99, 116, 102, 121, 118, 103, 117, 104, 98, 233, 233, 233, 232, 232, 13, 10 ]

po-jo avatar Jul 07 '18 12:07 po-jo

With v2 coming out, you should be able to change the encoding of the readable file stream given to you by multer.

@LinusU correct me if I'm wrong here!

ryhinchey avatar Apr 11 '20 02:04 ryhinchey

this is the code I'm using to solve this issue.

const multer = require('multer')

const fileFilter = (req, file, callback) => {
    // fix problem can't save arabic strings
    file.originalname = Buffer.from(file.originalname, 'latin1').toString('utf8');
    callback(null, true);
};

const upload = multer({ fileFilter });

this works too.

const  iconv = require('iconv-lite');
file.originalname = iconv.decode(Buffer.from(file.originalname, 'latin1'), 'utf8');

https://github.com/mscdex/busboy/issues/247

AnasQiblawi avatar Jan 17 '23 18:01 AnasQiblawi