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));
}