在Laravel中更改S3端点

Luc*_*ois 2 php amazon-s3 laravel-5

我使用filesystems.php文件来配置我的S3。当我尝试将内容放入存储桶时,出现以下错误:

Encountered a permanent redirect while requesting https://s3-us-west-2.amazonaws.com/MYBUCKET... Are you sure you are using the correct region for this bucket?
Run Code Online (Sandbox Code Playgroud)

然后,我尝试访问该网址,然后收到以下消息:

The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
Run Code Online (Sandbox Code Playgroud)

在同一页面上,我得到:

<Endpoint>s3.amazonaws.com</Endpoint>
Run Code Online (Sandbox Code Playgroud)

然后如何从Laravel生成的URL中删除该区域

geo*_*oom 6

您可以这样创建客户服务提供商:

use Illuminate\Support\ServiceProvider;
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;
use Aws\Laravel\AwsServiceProvider;
use Storage;

class AwsS3ServiceProvider extends ServiceProvider
{

    /**
     * Perform post-registration booting of services.
     *
     * @return void
     */
    public function boot()
    {
        Storage::extend('s3', function($app, $config) {
            $client = new S3Client([
                'credentials' => [
                    'key'    => $config['key'],
                    'secret' => $config['secret'],
                ],
                'region' => $config['region'],
                'version' => $config['version'],
                'endpoint' => $config['endpoint'],
                'ua_append' => [
                    'L5MOD/' . AwsServiceProvider::VERSION,
                ],
            ]);

            return new Filesystem(new AwsS3Adapter($client, $config['bucket_name']));
        });
    }

    /**
     * Register bindings in the container.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
Run Code Online (Sandbox Code Playgroud)

并添加endpoint变量到config/filesystems.php

's3' => [
    'driver' => 's3',
    'key'    => env('AWS_KEY'),
    'secret' => env('AWS_SECRET'),
    'region' => env('AWS_REGION'),
    'version' => 'latest',
    'endpoint' => env('AWS_ENDPOINT'),
    'bucket_name' => env('AWS_BUCKET_NAME')
]
Run Code Online (Sandbox Code Playgroud)

查看文档以获取有关如何扩展Storage Facade的详细信息。