Created
July 23, 2019 04:42
-
-
Save 1242035/ab1b7737fc860b868c1c4344f8cff122 to your computer and use it in GitHub Desktop.
Laravel Wasabi storage provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Storage; | |
use Aws\S3\S3Client; | |
use League\Flysystem\AwsS3v3\AwsS3Adapter; | |
use League\Flysystem\Filesystem; | |
use Illuminate\Support\ServiceProvider; | |
class WasabiServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// | |
} | |
/** | |
* Bootstrap services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
Storage::extend('wasabi', function ($app, $config) { | |
$conf = [ | |
'endpoint' => "https://" . $config['bucket'] . ".s3." . $config['region'] . ".wasabisys.com/", | |
'bucket_endpoint' => true, | |
'credentials' => [ | |
'key' => $config['key'], | |
'secret' => $config['secret'], | |
], | |
'region' => $config['region'], | |
'version' => 'latest', | |
]; | |
$client = new S3Client($conf); | |
$adapter = new AwsS3Adapter($client, $config['bucket'], $config['root']); | |
$filesystem = new Filesystem($adapter); | |
return $filesystem; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment