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.
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 );
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With