DataFlex
DataFlex
Google Cloud Storage: Update Object Metadata
See more Google Cloud Storage Examples
Demonstrates how to update (edit) the metadata associated with an object in a Google Cloud Storage bucket.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vBdRequestBody
Handle hoBdRequestBody
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Implements the following CURL command:
// curl -X PATCH --data-binary @JSON_FILE_NAME \
// -H "Authorization: Bearer OAUTH2_TOKEN" \
// -H "Content-Type: application/json" \
// "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME"
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
Get Create (RefClass(cComChilkatBinData)) To hoBdRequestBody
If (Not(IsComObjectCreated(hoBdRequestBody))) Begin
Send CreateComObject of hoBdRequestBody
End
Get ComLoadFile Of hoBdRequestBody "JSON_FILE_PATH" To iSuccess
If (iSuccess <> True) Begin
Showln "Failed to load JSON_FILE_PATH"
Procedure_Return
End
// Adds the "Authorization: Bearer OAUTH2_TOKEN" header.
Set ComAuthToken Of hoHttp To "OAUTH2_TOKEN"
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoBdRequestBody to vBdRequestBody
Get pvComObject of hoResp to vResp
Get ComHttpBd Of hoHttp "PATCH" "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME" vBdRequestBody "application/json" vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Procedure_Return
End
End_Procedure