How to set filename containing spaces in Content-Disposition header

Huy Than picture Huy Than · Sep 5, 2013 · Viewed 19.9k times · Source

I have this piece of code:

resp.addHeader("Content-Disposition", "inline; filename=" + fileName);

When the file name is "a_b_c.doc" or "abc.doc" the name of the downloaded file is displayed correctly. However, when the file name is "a b c .doc" the name of the downloaded file is only "a".

How can we solve this?

Answer

Moritz Petersen picture Moritz Petersen · Sep 5, 2013

Use quotes:

resp.addHeader("Content-Disposition", "inline; filename=\"" + fileName + "\"");