0

我尝试使用 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));
            }
4

1 回答 1

0

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

于 2013-09-12T11:42:32.583 回答