doufu1970 2013-09-12 07:10
浏览 125
已采纳

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

I try the following code Uploading an Image using AWS SDK for PHP 2, and it works for US Default Region (us-east-1), But when I create another bucket with Singapore Region ( I put ap-souteast-2 in the code) It returns error:

The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint: "mytestbucket.local.s3-ap-southeast-1.amazonaws.com".

How to solve this problem?

Here's my code

$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条回答 默认 最新

  • doumaqing6652 2013-09-12 11:42
    关注

    You need to use the ap-southeast-1 region and not ap-souteast-2 in the $awsConfig settings.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?