错误上传到S3存储桶,与EndPoint有关

时间:2013-09-12 07:10:44

标签: php amazon-s3

我尝试使用以下代码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));
            }

1 个答案:

答案 0 :(得分:0)

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