Support the ongoing development of Laravel.io →
posted 10 years ago
Requests
Last updated 2 years ago.
0

I posted an answer on StackOverflow:

See this issue: https://github.com/symfony/symfony/issues/6530 and this line: https://github.com/symfony/symfony/blob/2.4/src/Symfony/Compon...

It suggests to use BinaryFileResponse instead. Something like this:

$response = new Symfony\Component\HttpFoundation\BinaryFileResponse($file);
$response->setContentDisposition('inline');
$response->setTtl(300);
return $response;

//Or with setting the headers manually
return  new Symfony\Component\HttpFoundation\BinaryFileResponse($file, 200, $headers, true, 'inline');

//Or Laravel style:
return Response::download($file)->setTtl(300)->setContentDisposition('inline');
return Response::download($file, null, $headers)->setContentDisposition('inline');
Last updated 2 years ago.
0

That's perfect, thanks a ton! I wonder what the rationale was behind not checking to see if the Cache-Control was set before hard-coding it? In any event, it would have been nice if that little gotcha were documented somewhere. I swear, I've been Googling this for days and couldn't find a word about having this issue when trying to send binary files. Anyway, thanks again for the solution!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

TonyVz tonyvz Joined 8 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.