Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

daveb2's avatar
Level 3

response()->file() and response()->streamDownload() returning raw text

I'm seeing some strange behaviour on our live site, which is running on Digital Ocean behind a load balancer.

On the production site, running:

return response()->streamDownload(
				function() use ($resource) {
					echo Storage::get('path-to-file');
				}, $resource->file, [
					'Content-Type' => $resource->mime_type,
					'Content-Disposition' => 'inline; filename="' . $resource->file . '"'
				], 'inline');

Works as expected in Firefox where it shows an inline preview of the file (a PDF file in this case), but in Chrome & Edge it returns plain text beginning with:

%PDF-1.6
%âãÏÓ
269 0 obj
<</Linearized 1/L 276797/O 271/...

Does anybody know what might be causing this? The code is the same, and if I change 'inline' to 'attachment', the file downloads successfully.

I thought this issue might be related to being behind a proxy, or a file size set incorrectly, but the fact that it works in non-chrome browsers is confusing.

0 likes
2 replies
Merklin's avatar
Merklin
Best Answer
Level 7
  1. Make sure $resource->mime_type is returning application/pdf
  2. Try adding 'X-Content-Type-Options' => 'nosniff' after 'Content-Disposition'

Try if this static code works in Chrome

'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="' . addslashes($resource->file) . '"',
'X-Content-Type-Options' => 'nosniff'
1 like
daveb2's avatar
Level 3

@Merklin Sigh. It was the mime type being absent. Thanks so much Merklin.

1 like

Please or to participate in this conversation.