As of Laravel 5.5, the Storage
facade contains this functionality internally. Therefore, it is recommended to sign your URLs according to the way Laravel intends.
This package extends Laravel's S3 filesystem driver to return signed URLs via the Storage::url() command.
Via Composer
$ composer require jdavidbakr/signed-s3-filesystem
Once installed, add the following to your providers array in cofig/app.php:
jdavidbakr\SignedS3Filesystem\SignedS3FilesystemServiceProvider::class,
This package makes use of the AWS facade, so be sure you have the following set in your providers array:
Aws\Laravel\AwsServiceProvider::class,
as well as in your alias array:
'AWS' => Aws\Laravel\AwsFacade::class,
You will also need to add the driver information to your config/filesystems.php file. This driver uses the same info as the S3 driver, with an additional parameter for the length of time until the signed URL will expire. If you do not specify an expiration time, URLs will default to expire 2 hours after being generated.
's3-signed' => [
'driver' => 's3-signed',
'key' => 'your-key',
'secret' => 'your-secret',
'region' => 'your-region',
'bucket' => 'your-bucket',
'options' => [
'expiration'=>'time-to-expire-urls-in-seconds',
],
],
Because the expiration option is optional, and everything else acts the same as the standard S3 driver, you can alternatively just change the driver value of the existing s3 section to 's3-signed'.
Use this driver in the same manner as you would any other Laravel filesystem driver. The Storage::url() command will return a signed URL.
$signed_url = Storage::disk('s3-signed')->url('path-to-file');
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.