php - Laravel 8x Response download: binary files always 0 bytes
Solution:
Have you tried the following:
$path = Storage::disk('test')->url('whatever.pdf');
dump(strlen(File::get($path)); // 5115
if (File::exists($path)) {
return response()->download(Storage::disk('test')->path('whatever.pdf'));
}
The response()->download()
method needs an absolute path to the file which I believe the ->url()
wasn't providing.
Answer
Solution:
The request was being routed through a node micro server with the response being handled as text.
Handling the response as binary solved the issue. Previously, this server was only setup to send text.
res.buffer()
Source