Use of ("Content-Disposition", "inline; filename=" + fileName)

10k Views Asked by At

I have this problem in 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 correct. However, when the file name is : a b c.doc , the name of the downloaded file is only "a".

How can I work around this?

Many thanks!

3

There are 3 best solutions below

1
On

The spec explains this, and gives explicit examples with spaces in the file name.

1
On

Put quotes around the filename like this:

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

Concatenate the file name after perform the url encode on the file name string.