Lua
Lua
Initiate Resumable Upload Session
See more Google Cloud Storage Examples
Initiate a Google Cloud Storage resumable upload session..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()
local jsonToken = chilkat.JsonObject.new()
local success = jsonToken:load_file("qa_data/tokens/googleCloudStorage.json")
if not success then
print(jsonToken.last_error_text)
return
end
local jsonMetaData = chilkat.JsonObject.new()
jsonMetaData:update_string("contentType", "image/jpeg")
-- Adds the "Authorization: Bearer <access_token>" header..
http.auth_token = jsonToken:string_of("access_token")
http:set_url_var("bucket_name", "chilkat-bucket-b")
http:set_url_var("object_name", "penguins2.jpg")
local url = "https://storage.googleapis.com/upload/storage/v1/b/{$bucket_name}/o?uploadType=resumable&name={$object_name}"
local resp = chilkat.HttpResponse.new()
success = http:http_json("POST", url, jsonMetaData, "application/json", resp)
if not success then
print(http.last_error_text)
return
end
local statusCode = resp.status_code
print("response status code = " .. statusCode)
local sessionUrl = ""
if statusCode ~= 200 then
print(resp.body_str)
else
-- The session URL will be used to upload the file in chunks, in subsequent HTTP POSTs...
sessionUrl = resp:get_header_field("Location")
print("Session URL = " .. sessionUrl)
end