DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoRest
Boolean iBTls
Integer iPort
Boolean iBAutoReconnect
Variant vAuthAws
Handle hoAuthAws
Handle hoXml
Variant vSbRequestBody
Handle hoSbRequestBody
Variant vSbResponse
Handle hoSbResponse
String sTemp1
Integer iTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
// 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")
Move True To iBTls
Move 443 To iPort
Move True To iBAutoReconnect
Get ComConnect Of hoRest "s3.amazonaws.com" iPort iBTls iBAutoReconnect To iSuccess
// Provide AWS credentials.
Get Create (RefClass(cComChilkatAuthAws)) To hoAuthAws
If (Not(IsComObjectCreated(hoAuthAws))) Begin
Send CreateComObject of hoAuthAws
End
Set ComAccessKey Of hoAuthAws To "AWS_ACCESS_KEY"
Set ComSecretKey Of hoAuthAws To "AWS_SECRET_KEY"
Set ComServiceName Of hoAuthAws To "s3"
Set ComRegion Of hoAuthAws To "us-east-1"
Get pvComObject of hoAuthAws to vAuthAws
Get ComSetAuthAws Of hoRest vAuthAws To iSuccess
// 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.
Set ComHost Of hoRest To "chilkat100.s3.amazonaws.com"
Get Create (RefClass(cComChilkatXml)) To hoXml
If (Not(IsComObjectCreated(hoXml))) Begin
Send CreateComObject of hoXml
End
Set ComTag Of hoXml To "Tagging"
Send ComUpdateChildContent To hoXml "TagSet|Tag|Key" "plant"
Send ComUpdateChildContent To hoXml "TagSet|Tag|Value" "chili pepper"
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
Send CreateComObject of hoSbRequestBody
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComGetXmlSb Of hoXml vSbRequestBody To iSuccess
// It is important to add the terminating "=" after the "?tagging".
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponse
If (Not(IsComObjectCreated(hoSbResponse))) Begin
Send CreateComObject of hoSbResponse
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get pvComObject of hoSbResponse to vSbResponse
Get ComFullRequestSb Of hoRest "PUT" "/chiliPepper.gif?tagging=" vSbRequestBody vSbResponse To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "Response status code: " iTemp1
// When successful, the S3 Storage service will respond with a 200 response code,
// with an XML body.
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 <> 200) Begin
// Examine the request/response to see what happened.
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "response status code = " iTemp1
Get ComResponseStatusText Of hoRest To sTemp1
Showln "response status text = " sTemp1
Get ComResponseHeader Of hoRest To sTemp1
Showln "response header: " sTemp1
Get ComGetAsString Of hoSbResponse To sTemp1
Showln "response body: " sTemp1
Showln "---"
Get ComLastRequestStartLine Of hoRest To sTemp1
Showln "LastRequestStartLine: " sTemp1
Get ComLastRequestHeader Of hoRest To sTemp1
Showln "LastRequestHeader: " sTemp1
End
Get ComGetAsString Of hoSbResponse To sTemp1
Showln sTemp1
Showln "Success."
End_Procedure