PowerBuilder
PowerBuilder
S3 Add Tags to an Object
See more Amazon S3 (new) Examples
Demonstrates how to add one or more tags to an S3 object.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Rest
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_AuthAws
oleobject loo_Xml
oleobject loo_SbRequestBody
oleobject loo_SbResponse
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
// Connect to the Amazon AWS REST server in the desired region.
// (for us-east-1, we use "s3.amazonaws.com", but for another region, such as us-west-2, we would use "s3-us-west-2.amazonaws.com")
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("s3.amazonaws.com",li_Port,li_BTls,li_BAutoReconnect)
// Provide AWS credentials.
loo_AuthAws = create oleobject
li_rc = loo_AuthAws.ConnectToNewObject("Chilkat.AuthAws")
loo_AuthAws.AccessKey = "AWS_ACCESS_KEY"
loo_AuthAws.SecretKey = "AWS_SECRET_KEY"
loo_AuthAws.ServiceName = "s3"
loo_AuthAws.Region = "us-east-1"
loo_Rest.SetAuthAws(loo_AuthAws)
// Set the bucket name via the HOST header.
// In this case, the bucket name is "chilkat100".
// Note that the Host header should use "bucketName.s3.amazonaws.com", not "bucketName.s3-us-east-1.amazonaws.com"
// The same applies to aother regions. The Host header should simply be <bucketName>.s3.amazonaws.com regardless of the region.
loo_Rest.Host = "chilkat100.s3.amazonaws.com"
loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")
loo_Xml.Tag = "Tagging"
loo_Xml.UpdateChildContent("TagSet|Tag|Key","plant")
loo_Xml.UpdateChildContent("TagSet|Tag|Value","chili pepper")
loo_SbRequestBody = create oleobject
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Xml.GetXmlSb(loo_SbRequestBody)
// It is important to add the terminating "=" after the "?tagging".
loo_SbResponse = create oleobject
li_rc = loo_SbResponse.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Rest.FullRequestSb("PUT","/chiliPepper.gif?tagging=",loo_SbRequestBody,loo_SbResponse)
if li_Success = 0 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_AuthAws
destroy loo_Xml
destroy loo_SbRequestBody
destroy loo_SbResponse
return
end if
Write-Debug "Response status code: " + string(loo_Rest.ResponseStatusCode)
// When successful, the S3 Storage service will respond with a 200 response code,
// with an XML body.
if loo_Rest.ResponseStatusCode <> 200 then
// Examine the request/response to see what happened.
Write-Debug "response status code = " + string(loo_Rest.ResponseStatusCode)
Write-Debug "response status text = " + loo_Rest.ResponseStatusText
Write-Debug "response header: " + loo_Rest.ResponseHeader
Write-Debug "response body: " + loo_SbResponse.GetAsString()
Write-Debug "---"
Write-Debug "LastRequestStartLine: " + loo_Rest.LastRequestStartLine
Write-Debug "LastRequestHeader: " + loo_Rest.LastRequestHeader
end if
Write-Debug loo_SbResponse.GetAsString()
Write-Debug "Success."
destroy loo_Rest
destroy loo_AuthAws
destroy loo_Xml
destroy loo_SbRequestBody
destroy loo_SbResponse