I am trying to copy a S3 object from one bucket to another and the response is looks like this -
`object(stdClass)#24 (3) {
["error"]=> array(2) {
["code"]=> string(9)
"NoSuchKey" ["message"]=> string(33)
"The specified key does not exist."
}
["code"]=> int(404) ["headers"]=> array(1) {
["type"]=> string(15) "application/xml"
}
}
`
Here is how the code looks -
var_dump($this->s3->copyObject('bucket_1','bucket_1/'. images/1.jpg, 'bucket_2', 'bucket_2/images')).die();
According to method signature of copyObject I would need to supply Source object URI and Destination object URI.
Anyone please help me to know what's going wrong here ?
Thanks.
To copy an object between buckets, you must make sure that the correct permissions are configured. To copy an object between buckets in the same AWS account, you can set permissions using IAM policies.
You can't transfer Amazon S3 bucket ownership between AWS accounts because the bucket is always owned by the account that created it. Instead, you can copy Amazon S3 objects from one bucket to another so that you give ownership of the copied objects to the destination account.
Finally I fixed it after few hours of looking into amazon docs.
Here is what S3 Object keys are -http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-keys
As S3 is a flat file system, the folders are includes in keys,
$this->s3->copyObject('bucket_1','images/1.jpg, 'bucket_2', 'images/copy_of_2.jpg');
ACL can also be passed as a fifth parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With