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"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
set rest = Server.CreateObject("Chilkat_9_5_0.Rest")
set authAws = Server.CreateObject("Chilkat_9_5_0.AuthAws")
authAws.AccessKey = "AWS_ACCESS_KEY"
authAws.SecretKey = "AWS_SECRET_KEY"
authAws.Region = "us-west-2"
authAws.ServiceName = "s3"
success = 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) Then
Response.Write "<pre>" & Server.HTMLEncode( "ConnectFailReason: " & rest.ConnectFailReason) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"
Response.End
End If
success = rest.AddHeader("x-amz-copy-source","/chilkat.qa/starfish.jpg")
set sbResponseBody = Server.CreateObject("Chilkat_9_5_0.StringBuilder")
success = rest.FullRequestNoBodySb("PUT","/starfishCopy.jpg",sbResponseBody)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"
Response.End
End If
respStatusCode = rest.ResponseStatusCode
If (respStatusCode >= 400) Then
Response.Write "<pre>" & Server.HTMLEncode( "Response Status Code = " & respStatusCode) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Response Header:") & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( rest.ResponseHeader) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Response Body:") & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( sbResponseBody.GetAsString()) & "</pre>"
Response.End
End If
set xmlResponse = Server.CreateObject("Chilkat_9_5_0.Xml")
success = 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")
%>
</body>
</html>
<?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>