You are viewing the documentation for an older version of this package. You can check the version you are using with the following command:
composer show spatie/laravel-medialibrary
If you want to output your $media
instance to the browser, you may use the toResponse
& toInlineResponse
methods.
use Illuminate\Http\Request;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
public function download(Request $request, Media $media)
{
return $media->toResponse($request);
}
By using toResponse
, your browser is instructed to download the file with the attachment
Content-Disposition.
If you want to output your $media
instance to your browser, but want to inline render it, you may use toInlineResponse
use Illuminate\Http\Request;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
public function download(Request $request, Media $media)
{
return $media->toInlineResponse($request);
}
The toInlineResponse
method instructs your browser to inline render the file by setting the Content-Disposition to inline
.
Both methods use a streaming adapter to ensure low memory usage.