简体   繁体   中英

Storage facade get method in returns File not found at path while file exists - Laravel 5.5

I have added a local disk to my filesystems config

 'customDisk' => 
[
 'driver' => 'local',
 'root' => 'D:\RandomFolder',
],

In my DB Seeder I have the following line

$file = Storage::disk('customDisk')->get($filename);

and I get the following error - File not found at path: path/name.

The thing is that the file does exist and I can't understand why this throws an error.

I am aware that I can use File:: facade, but I'm having other concerns about it and thus I'd rather not use it.

From your previous comment, I can see the problem now. You say your files returns content of the file, which probably contains size, mimeType, path and so on. So, you either have to read only path of that variable, or decode it before you use it in storage:

Storage::disk('customDisk')->get($filename->path)

or:

$file = json_decode($filename); 
$path = $file->path;
Storage::disk('customDisk')->get($path);

Didn't test it, but this should give you desired output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM