Laravel – Streaming video from storage directory

  laravel, php, stream, streaming, video-streaming

I did exactly what these links explain:

https://laravel.io/forum/10-06-2014-streaming-video-files-with-laravel

https://gist.github.com/vluzrmos/993d400739dd2e9aa47d

Retrieve video from Laravel Storage

NONE OF THEM WORKED!

My code:

View:

<video controls>
    <source src="{{ $package->video }}" type="video/mp4">
</video>


Model:

public function getVideoAttribute() {
    // 1:
    $path = storage_path('app/package/video.mp4');
    $stream = new AppHelpersVideoStream($path);
    $stream->start();

    // 2:
    $fileContents = Storage::disk('local')->get('app/package/video.mp4');
    $response = Response::make($fileContents, 200);
    $response->header('Content-Type', "video/mp4");

    return $response;
}

and the results:

stream video 1 As you can see it is empty.

stream video 2 And this one doesn’t even let the page load and returns the page as an empty video.

Source: Laravel

Leave a Reply