I suggest do a search from @martinbean he has had some detailed replies on the subject. I don't have the links.
Feb 26, 2023
3
Level 15
Streaming a video file from S3, to be played in the browser
How would I accomplish streaming files from S3? Right now, I receive a 502 whenever the tasks times out, or a 513. Currently, when I attempt to stream the file, I've done as such:
public function show(Company $company, Video $video)
{
$video = $company->videos()->where('id', $video->id)->get()->first();
if (! request()->user()->can('view', $video)) {
abort(403);
}
Log::debug($video->file_path);
Log::debug(Storage::disk('s3')->get($video->file_path));
$stream = Storage::disk('s3')->readStream($video->file_path);
return response(Storage::disk('s3')->get($video->file_path), 200, [
'Content-Type' => 'video/mp4',
'Content-Disposition' => 'inline; filename="'.$video->file_path.'"',
]);
}
But it seems like it's fetching the video, and then allows the user to see it, if it loads successfully.
Please or to participate in this conversation.