0

I'm using S3 to store my files. I have a video saved in my directory. I want to take the video from S3 and save it to a record in my DB. This is the code I'm using:

$file = Storage::get('input/TESTING.mp4');
            
$newer->video = $file;

I'm getting this error (which comes from the second line of my code):

file_exists() expects parameter 1 to be a valid path, string given

The file does exist, I'm 100% sure, Laravel is finding it. I used the Storage::exists() function to test that.

I'm not sure what the problem is, any help would be appreciated.

SebastianSrvn
  • 103
  • 1
  • 4
  • Could you show the code actually throwing the error? How is the second line throwing the error? What happens in the `$newer` object? What you get from Storage is an S3 link, not necessarily a path. You can check by dumping the $file variable – Maarten Veerman Feb 04 '21 at 21:45

1 Answers1

0

The method Storage::get returns the content of the file and not the location. You can see it on the documentation.

To get the path, you should do something like that:

$path = Storage::disk('local')->getDriver()->getAdapter()->applyPathPrefix('filename.png');

Or, since Laravel 5.4:

$path = Storage::disk('public')->path('filename.png');

More details:

How to get file URL using Storage facade in laravel 5?

Lucius
  • 1,253
  • 1
  • 6
  • 17