Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 file downloads invalid

When using Response::download to download files, I noticed that images and other binary files were being transferred incorrectly.

Changing the Content-Type header didn't change anything, nor did explicitly disallowing cache or forcing the content's length.

What may be the cause of this problem?

like image 596
Danny Kopping Avatar asked Apr 27 '15 21:04

Danny Kopping


1 Answers

The solution to this problem can be found here:

http://simpledeveloper.com/how-to-fix-laravel-response-image-download-in-laravel/

The cause of the issue was due to Laravel/Symfony not properly cleaning the output buffer for some reason, so the solution is this:

$response = Response::download($path, ...);
ob_end_clean();

return $response;
like image 85
Danny Kopping Avatar answered Oct 06 '22 01:10

Danny Kopping