I'm struggling with wrong encoded multipart form filenames uploaded to a nodejs backend.
Running the node application locally works as expected and the filenames arrive with propert utf-8 encoding. As soon as i run the application in a docker environment the backend receives scrambled filenames.
I'm using the express-fileupload
package.
JSON Content in the same request is properly encoded..
Backend:
router.post('/upload', async (req: any, res) => {
let formDataFiles = req.files;
});
http response header seems correct as well: content-type application/json; charset=utf-8
I'm not sure where to look. Where does nodejs take the encoding from?
Ok i found the solution. express-fileupload
uses busboy under the hood. You can pass in busboy options and one of them is defParamCharset
:
"For multipart forms, the default character set to use for values of part header parameters (e.g. filename) that are not extended parameters (that contain an explicit charset)."
The documentation states Default: 'latin1'.
but in my case it was dependent on the running OS!
If you initialize the middleware as following it should properly UTF8 encode filenames:
app.use(fileUpload({
defCharset: 'utf8',
defParamCharset: 'utf8'
}));