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

前端 未结 13 811
庸人自扰
庸人自扰 2020-11-30 22:40

I\'ve been experimenting using the new Flysystem integration with Laravel 5. I am storing \'localised\' paths to the DB, and getting the Storage facade to complete the path

13条回答
  •  旧时难觅i
    2020-11-30 23:37

    Edit: Solution for L5.2+

    There's a better and more straightforward solution.

    Use Storage::url($filename) to get the full path/URL of a given file. Note that you need to set S3 as your storage filesystem in config/filesystems.php: 'default' => 's3'

    Of course, you can also do Storage::disk('s3')->url($filename) in the same way.

    As you can see in config/filesystems.php there's also a parameter 'cloud' => 's3' defined, that refers to the Cloud filesystem. In case you want to mantain the storage folder in the local server but retrieve/store some files in the cloud use Storage::cloud(), which also has the same filesystem methods, i.e. Storage::cloud()->url($filename).

    The Laravel documentation doesn't mention this method, but if you want to know more about it you can check its source code here.

提交回复
热议问题