Lua
Lua
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 Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- 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
local bdRequestBody = chilkat.BinData.new()
local success = bdRequestBody:load_file("JSON_FILE_PATH")
if not success then
print("Failed to load JSON_FILE_PATH")
return
end
-- Adds the "Authorization: Bearer OAUTH2_TOKEN" header.
http.auth_token = "OAUTH2_TOKEN"
local resp = chilkat.HttpResponse.new()
success = http:http_bd("PATCH", "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME", bdRequestBody, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false
print("Response Body:")
print(jResp:emit())
local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(resp.header)
print("Failed.")
return
end