-
Is there any way to get file content from media item? I need to get file content from a media item, but have problems dealing with different disks. For example: $media = \Spatie\MediaLibrary\Models\Media::first();
$file_content = Storage::disk($media->disk)->get($media->getPath()); // Will work on S3 disk, fails on local disk On S3 disk, Any way to get file content no matter disk type? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Use a custom macro for choose wich path use, or use a custom path generator for make relative paths on local disk |
Beta Was this translation helpful? Give feedback.
-
Does a PR that implements |
Beta Was this translation helpful? Give feedback.
-
I needed this and this is how I did it:
|
Beta Was this translation helpful? Give feedback.
-
Hi @Norris1z I have used something like this: function getMediaContent(Media $media)
{
return config("filesystems.disks.{$media->disk}.driver") === 'local'
? file_get_contents($media->getPath())
: Storage::disk($media->disk)->get($media->getPath());
} But your answer seems beeter! |
Beta Was this translation helpful? Give feedback.
I needed this and this is how I did it: