· 7 years ago · Apr 21, 2018, 11:00 AM
1<?php
2
3/**
4 * @file
5 * Usage:
6 * 1. remove the V3 AWS PHP sdk when present
7 * composer remove "league/flysystem-aws-s3-v3"
8 * 2. install the V3 AWS PHP sdk when present
9 * composer require "league/flysystem-aws-s3-v2"
10 * 3. Add the provider to your config/app.php:
11 * 'providers' => [
12 * // Other Service Providers
13 * App\Providers\S3v2ServiceProvider::class,
14 * ],
15 * 4. Add your S3 credentials to config/filesystems.php:
16 * 'disks' => [
17 * 'remote' => [
18 * 'driver' => 's3v2',
19 * 'key' => 'ACCESS_KEY',
20 * 'secret' => 'SECRET_KEY',
21 * 'bucket' => 'BUCKET_NAME',
22 * 'base_url' => 'BASE_URL'
23 * ],
24 * ],
25 */
26
27namespace App\Providers;
28
29use Aws\S3\S3Client;
30use Illuminate\Support\Facades\Storage;
31use Illuminate\Support\ServiceProvider;
32use League\Flysystem\AwsS3v2\AwsS3Adapter;
33use League\Flysystem\Filesystem;
34
35class S3v2ServiceProvider extends ServiceProvider
36{
37 /**
38 * Bootstrap the application services.
39 *
40 * @return void
41 */
42 public function boot()
43 {
44 Storage::extend('s3v2', function ($app, $config) {
45
46 $client = S3Client::factory([
47 'key' => $config['key'],
48 'secret' => $config['secret'],
49 'base_url' => $config['base_url']
50 ]);
51 return new Filesystem(new AwsS3Adapter($client, $config['bucket']));
52 });
53 }
54
55 /**
56 * Register the application services.
57 *
58 * @return void
59 */
60 public function register()
61 {
62 //
63 }
64}