Demonstrates how to copy an S3 file from one bucket to another. The file can also be renamed if desired. (The file already exists in S3 in one bucket, and is copied without downloading/uploading to another S3 bucket.) This example copies from /chilkat.qa/starfish.jpg to /chilkat.ocean/starfishCopy.jpg
curl -X PUT https://chilkat.ocean.s3.us-west-2.amazonaws.com/starfishCopy.jpg \
-H "x-amz-copy-source: /chilkat.qa/starfish.jpg"
use chilkat();
$rest = chilkat::CkRest->new();
$authAws = chilkat::CkAuthAws->new();
$authAws->put_AccessKey("AWS_ACCESS_KEY");
$authAws->put_SecretKey("AWS_SECRET_KEY");
$authAws->put_Region("us-west-2");
$authAws->put_ServiceName("s3");
$rest->SetAuthAws($authAws);
# URL: https://chilkat.ocean.s3.us-west-2.amazonaws.com/starfishCopy.jpg
$bTls = 1;
$port = 443;
$bAutoReconnect = 1;
$success = $rest->Connect("chilkat.ocean.s3.us-west-2.amazonaws.com",$port,$bTls,$bAutoReconnect);
if ($success != 1) {
print "ConnectFailReason: " . $rest->get_ConnectFailReason() . "\r\n";
print $rest->lastErrorText() . "\r\n";
exit;
}
$rest->AddHeader("x-amz-copy-source","/chilkat.qa/starfish.jpg");
$sbResponseBody = chilkat::CkStringBuilder->new();
$success = $rest->FullRequestNoBodySb("PUT","/starfishCopy.jpg",$sbResponseBody);
if ($success != 1) {
print $rest->lastErrorText() . "\r\n";
exit;
}
$respStatusCode = $rest->get_ResponseStatusCode();
if ($respStatusCode >= 400) {
print "Response Status Code = " . $respStatusCode . "\r\n";
print "Response Header:" . "\r\n";
print $rest->responseHeader() . "\r\n";
print "Response Body:" . "\r\n";
print $sbResponseBody->getAsString() . "\r\n";
exit;
}
$xmlResponse = chilkat::CkXml->new();
$xmlResponse->LoadSb($sbResponseBody,1);
# See the Online Tool for Generating XML Parse Code
$CopyObjectResult_xmlns = $xmlResponse->getAttrValue("xmlns");
$LastModified = $xmlResponse->getChildContent("LastModified");
$ETag = $xmlResponse->getChildContent("ETag");
<?xml version="1.0" encoding="UTF-8"?>
<CopyObjectResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<LastModified>2018-12-18T15:53:32.000Z</LastModified>
<ETag>"2e9c59dbf2662367dc97dfdda85da048"</ETag>
</CopyObjectResult>