-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.6] Add stream download response #22777
[5.6] Add stream download response #22777
Conversation
For reference, this is a resubmission of #22764 to |
Is anything actually being streamed here? Doesn't |
@taylorotwell The file_get_contents above is an example, the important thing is that this PR allows developers to return anything the callable returns as an attachament. Imagine I'm using the GitHub API to get the readme of this repo. Now I can "stream" the file from memory instead of saving it to a file and returning the file: <?php
Route::get('/', function () {
return response()->streamDownload(function () {
echo GitHub::api('repo')->contents()->readme('laravel', 'laravel')['contents']
}, 'laravel-readme.md');
}); |
Thanks for the PR review. Yeah @m1guelpf has explained the PR perfectly. Just to add a little more context, this PR was born out of this Stackoverflow question where people were looking to use the "download" response with remote files and I thought the "stream" response would be the best way to achieve that. @m1guelpf You could be right about the |
@TheoKouzelis Yeah, you're rigth. It makes sense, you have to use echo. |
Not sure if this helps, but we can also see this case on the League Glide Symfony response which is also used by the Glide Laravel integration: Note: If I'm not mistaken, also the dev should know how to write the streamed response closure, like for example when using Hope it helps 😄 |
Thanks for merging the PR @taylorotwell If we don't include the contract change. Would it be worth me back porting this to the other 5.x branches? |
Is this method works for large files, like hd movies (1080p) |
Adds the ability to respond with remote files as downloads.