VBScript
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' This example assumes the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
set http = CreateObject("Chilkat.Http")
' 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
set bdRequestBody = CreateObject("Chilkat.BinData")
success = bdRequestBody.LoadFile("JSON_FILE_PATH")
If (success <> 1) Then
outFile.WriteLine("Failed to load JSON_FILE_PATH")
WScript.Quit
End If
' Adds the "Authorization: Bearer OAUTH2_TOKEN" header.
http.AuthToken = "OAUTH2_TOKEN"
set resp = CreateObject("Chilkat.HttpResponse")
success = http.HttpBd("PATCH","https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME",bdRequestBody,"application/json",resp)
If (success = 0) Then
outFile.WriteLine(http.LastErrorText)
WScript.Quit
End If
set sbResponseBody = CreateObject("Chilkat.StringBuilder")
success = resp.GetBodySb(sbResponseBody)
set jResp = CreateObject("Chilkat.JsonObject")
success = jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = 0
outFile.WriteLine("Response Body:")
outFile.WriteLine(jResp.Emit())
respStatusCode = resp.StatusCode
outFile.WriteLine("Response Status Code = " & respStatusCode)
If (respStatusCode >= 400) Then
outFile.WriteLine("Response Header:")
outFile.WriteLine(resp.Header)
outFile.WriteLine("Failed.")
WScript.Quit
End If
outFile.Close