Php 更改Laravel中的S3端点
我使用filesystems.php文件来配置我的S3。 当我尝试将内容放入存储桶时,我收到以下错误:Php 更改Laravel中的S3端点,php,amazon-s3,laravel-5,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? 然后我尝试访问url,并收到以下消息: The bucket you ar
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?
然后我尝试访问url,并收到以下消息:
The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
在同一页上,我看到:
<Endpoint>s3.amazonaws.com</Endpoint>
s3.amazonaws.com
然后如何从Laravel生成的URL中删除该区域?您可以使用此软件包
在此包中,您可以根据需要在配置文件中指定设置 特定的bucket不是在AWS中创建的,因此请在AWS中创建一个bucket,并在文件系统配置中使用相同的bucket,问题将得到解决。您可以创建这样的客户服务提供商:
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()
{
//
}
}
并将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')
]
查看以获取详细信息。最简单的方法是创建一个新磁盘,该磁盘使用
config/filesystems.php
中的S3驱动程序。您不需要创建服务提供商-S3驱动程序将从磁盘配置(如果提供)中拾取端点
'spaces' => [
'driver' => 's3',
'key' => env('DO_SPACES_KEY'),
'secret' => env('DO_SPACES_SECRET'),
'endpoint' => 'https://nyc3.digitaloceanspaces.com',
'region' => 'nyc3',
'bucket' => env('DO_SPACES_BUCKET'),
],
将DO\u SPACES\u KEY
、DO\u SPACES\u SECRET
和DO\u SPACES\u BUCKET
环境变量设置为适当的值
来源:我可以知道S3文件系统驱动程序使用的是哪个软件包吗?league/flysystem-aws-S3-v3~1.0目前,您不需要添加自定义服务提供商来使用“endpoint”配置选项。@Artistan太好了,您可以对这个答案进行一些更新吗?