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.