Skip to content

Instantly share code, notes, and snippets.

@1242035
Created July 23, 2019 04:42
Show Gist options
  • Save 1242035/ab1b7737fc860b868c1c4344f8cff122 to your computer and use it in GitHub Desktop.
Save 1242035/ab1b7737fc860b868c1c4344f8cff122 to your computer and use it in GitHub Desktop.
Laravel Wasabi storage provider
<?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