Go
Go
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 Go Downloads
success := false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := chilkat.NewHttp()
// 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
bdRequestBody := chilkat.NewBinData()
success = bdRequestBody.LoadFile("JSON_FILE_PATH")
if success != true {
fmt.Println("Failed to load JSON_FILE_PATH")
http.DisposeHttp()
bdRequestBody.DisposeBinData()
return
}
// Adds the "Authorization: Bearer OAUTH2_TOKEN" header.
http.SetAuthToken("OAUTH2_TOKEN")
resp := chilkat.NewHttpResponse()
success = http.HttpBd("PATCH","https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME",bdRequestBody,"application/json",resp)
if success == false {
fmt.Println(http.LastErrorText())
http.DisposeHttp()
bdRequestBody.DisposeBinData()
resp.DisposeHttpResponse()
return
}
sbResponseBody := chilkat.NewStringBuilder()
resp.GetBodySb(sbResponseBody)
jResp := chilkat.NewJsonObject()
jResp.LoadSb(sbResponseBody)
jResp.SetEmitCompact(false)
fmt.Println("Response Body:")
fmt.Println(*jResp.Emit())
respStatusCode := resp.StatusCode()
fmt.Println("Response Status Code = ", respStatusCode)
if respStatusCode >= 400 {
fmt.Println("Response Header:")
fmt.Println(resp.Header())
fmt.Println("Failed.")
http.DisposeHttp()
bdRequestBody.DisposeBinData()
resp.DisposeHttpResponse()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()
return
}
http.DisposeHttp()
bdRequestBody.DisposeBinData()
resp.DisposeHttpResponse()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()