【问题标题】:Error upload to S3 bucket, something with EndPoint上传到 S3 存储桶时出错,与 EndPoint 相关
【发布时间】:2013-09-12 07:10:43
【问题描述】:

我尝试使用以下代码 Uploading an Image using AWS SDK for PHP 2,它适用于美国默认区域 (us-east-1),但是当我使用新加坡区域创建另一个存储桶时(我将 ap-souteast-2 放入代码中)它返回错误:

您尝试访问的存储桶必须使用 指定的端点。请将所有未来的请求发送到此端点: “mytestbucket.local.s3-ap-southeast-1.amazonaws.com”。

如何解决这个问题?

这是我的代码

$awsConfig = array(
                'key' => $this->container->getParameter('aws_key'),
                'secret' => $this->container->getParameter('aws_secret_key'),
                'region' => $this->container->getParameter('s3_region'),
            );
            $s3 = S3Client::factory($awsConfig);
            $bucketLists = array();
            try {
                $bucketname   = $this->container->getParameter('aws_bucket_name');
                $bucketFolder = $this->container->getParameter('upload_folder');
                $filename     = $user->getProfilePic();
                $fullfilename = $user->getAbsolutePath();

                $s3->putObject(array(
                    'Bucket' => $bucketname,
                    'Key'    => $bucketFolder.'/'.$filename, 
                    'Body'   => EntityBody::factory(fopen($fullfilename, 'r')),
                    'ACL'    => CannedAcl::PUBLIC_READ,
                    'ContentType' => mime_content_type($fullfilename)
                ));
                if (file_exists($fullfilename)) {
                    unlink($fullfilename);
                }
            } catch (S3Exception $e) {
                return $this->handleView( $this->view(array(
                'StatusCode' => 400, 
                'ErrorDesc' => $e->getMessage()), 400));
            }

【问题讨论】:

    标签: php amazon-s3


    【解决方案1】:

    您需要在$awsConfig 设置中使用ap-southeast-1 区域而不是ap-souteast-2

    【讨论】:

    • 我没有意识到这一点。感谢您的帮助。
    猜你喜欢
    • 2017-10-04
    • 2018-08-19
    • 2015-05-05
    • 2017-04-19
    • 2019-02-01
    • 1970-01-01
    • 2015-10-28
    • 2016-03-18
    • 2021-09-09
    相关资源
    最近更新 更多