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

Foks's avatar
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.

0 likes
3 replies
jlrdw's avatar

I suggest do a search from @martinbean he has had some detailed replies on the subject. I don't have the links.

maryhodge's avatar

To efficiently stream video files from S3 and address the timeout issues, consider using Laravel's response()->stream method for a more dynamic streaming approach. This allows for streaming content directly from the storage without loading the entire file into memory. Additionally, ensure that your S3 bucket is properly configured for serving video content. The 502 and 513 errors may be indicative of network or server issues, so reviewing your server and network configurations is advisable. In the context of watching premium movies, optimizing the streaming process ensures a seamless and premium user experience, reducing the likelihood of timeouts and errors during playback.You need to visit this site for more information........ https://www.loklokofficial.com/loklok-mod-apk/

zenish's avatar

To stream video files from S3 efficiently and resolve timeout issues, it's recommended to use Laravel's response()->stream method for a more dynamic streaming approach. This method streams content directly from storage without loading the entire file into memory. Ensure your S3 bucket is properly set up for video delivery. Errors like 502 and 513 may point to network or server problems, so it’s important to review your server and network configurations. When it comes to streaming premium content, such as watching movies, optimizing the process enhances user experience by reducing playback issues. Similarly, Roblox also emphasizes smooth, optimized streaming for seamless gameplay. Visit to learn more information.

Please or to participate in this conversation.