5

In Safari, my CSV files are being shown in the browser instead of downloading them using the Save As window.

I tried: response.setContentType("text/csv; charset=UTF-8");. The other browsers are fine with the second option, but Safari kept displaying the file in-browser instead of prompting the user to save it.

By the way, i'm running Liferay.

I fixed it by including this: response.setContentType("application/csv; charset=UTF-8");

Thanks.

user1916494
  • 73
  • 1
  • 1
  • 5

2 Answers2

2

text/csv would be the most appropriate for the content type. You also want to set the content-disposition like this:

response.setHeader( "Content-Disposition", "attachment;filename=" + filename );
Jeffrey Ray
  • 1,244
  • 2
  • 9
  • 20
2

I think you'll need to set the Content-Disposition HTTP header as well.

The HTTP header should look like this:

Content-Disposition: attachment; filename=WHATEVER_FILENAME_YOU_WANT

Does the response object have a setContentDisposition method too?

Community
  • 1
  • 1
Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270