Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome adds "-, attachment" to downloaded file

I use Symfony2 Framework and use the following code to export an xml file:

$response->setStatusCode(200);
$response->headers->set('Content-Type', 'application/xml');
$response->headers->set('Content-Description', 'Submissions Export');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename .'"');
$response->headers->set('Content-Transfer-Encoding', 'binary');
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Expires', '0');

I does not matter whether I take "Content-Transfer-Encoding" or "Pragma" or all of them except "Content-Type" and "Content-Disposition" away. The result in Chrome is always: "filename-, attachment" (without the "). In Firefox this works fine.

So for instance, if I have a file called home.xml Firefox will download home.xml, whereas Chrome will give me home.xml-, attachment.

like image 302
Micha Avatar asked Nov 07 '13 11:11

Micha


1 Answers

I know this is a pretty old discussion, but if anyone gets here looking for help with this, I determined that chrome seems to want a semicolon at the end of the filename and then it's happy. As in (VBScript):

Response.AddHeader "Content-Disposition", "attachment;filename=Something.xls;"

That fixed it for me. -Dave

like image 59
dnrayzn Avatar answered Sep 24 '22 16:09

dnrayzn