Sample code for 30+ languages & platforms
PowerShell

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 PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

$http = New-Object 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

$bdRequestBody = New-Object Chilkat.BinData
$success = $bdRequestBody.LoadFile("JSON_FILE_PATH")
if ($success -ne $true) {
    $("Failed to load JSON_FILE_PATH")
    exit
}

# Adds the "Authorization: Bearer OAUTH2_TOKEN" header.
$http.AuthToken = "OAUTH2_TOKEN"

$resp = New-Object Chilkat.HttpResponse
$success = $http.HttpBd("PATCH","https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME",$bdRequestBody,"application/json",$resp)
if ($success -eq $false) {
    $($http.LastErrorText)
    exit
}

$sbResponseBody = New-Object Chilkat.StringBuilder
$resp.GetBodySb($sbResponseBody)

$jResp = New-Object Chilkat.JsonObject
$jResp.LoadSb($sbResponseBody)
$jResp.EmitCompact = $false

$("Response Body:")
$($jResp.Emit())

$respStatusCode = $resp.StatusCode
$("Response Status Code = " + $respStatusCode)
if ($respStatusCode -ge 400) {
    $("Response Header:")
    $($resp.Header)
    $("Failed.")
    exit
}