6

express response.download filename is not support utf-8.

I wanna download file, file naming utf-8 (not english)

I already try Content-Disposition set to header

like this...

res.set "Content-Disposition", "attachment;filename=테스트 한글.hwp"

but not working...

LostCode
  • 533
  • 2
  • 6
  • 25
  • 1
    possible duplicate of [How to encode the filename parameter of Content-Disposition header in HTTP?](http://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http) – mscdex May 27 '14 at 17:58
  • also see [this](http://greenbytes.de/tech/tc2231/#attwithfn2231utf8). – mscdex May 27 '14 at 18:05

4 Answers4

14
var newFileName = encodeURIComponent("테스트 한글.hwp");
res.setHeader('Content-Disposition', 'attachment;filename*=UTF-8\'\''+newFileName);

This should do the trick. It helps me with polish diacritics. Note the =UTF-8\'\' part.

Artur Czyżewski
  • 705
  • 5
  • 12
2

Try this:

res.set("Content-Disposition", "attachment;filename=" + encodeURI("테스트 한글.hwp"));
0

Here is a popular library for UTF8 encoding/decoding https://www.npmjs.com/package/utf8

res.setHeader('Content-disposition', 'attachment; filename='+utf8.encode(object.pdfFileName));
PPB
  • 2,937
  • 3
  • 17
  • 12
0

https://www.npmjs.com/package/content-disposition

res.set("Content-Disposition", contentDisposition("테스트 한글.hwp")
const {
  parameters: { filename }
} = contentDisposition.parse(resp.headers['content-disposition'])
hojin
  • 1,221
  • 14
  • 16