Tcl
Tcl
Initiate Resumable Upload Session
See more Google Cloud Storage Examples
Initiate a Google Cloud Storage resumable upload session..Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set http [new_CkHttp]
set jsonToken [new_CkJsonObject]
set success [CkJsonObject_LoadFile $jsonToken "qa_data/tokens/googleCloudStorage.json"]
if {$success == 0} then {
puts [CkJsonObject_lastErrorText $jsonToken]
delete_CkHttp $http
delete_CkJsonObject $jsonToken
exit
}
set jsonMetaData [new_CkJsonObject]
CkJsonObject_UpdateString $jsonMetaData "contentType" "image/jpeg"
# Adds the "Authorization: Bearer <access_token>" header..
CkHttp_put_AuthToken $http [CkJsonObject_stringOf $jsonToken "access_token"]
CkHttp_SetUrlVar $http "bucket_name" "chilkat-bucket-b"
CkHttp_SetUrlVar $http "object_name" "penguins2.jpg"
set url "https://storage.googleapis.com/upload/storage/v1/b/{$bucket_name}/o?uploadType=resumable&name={$object_name}"
set resp [new_CkHttpResponse]
set success [CkHttp_HttpJson $http "POST" $url $jsonMetaData "application/json" $resp]
if {$success == 0} then {
puts [CkHttp_lastErrorText $http]
delete_CkHttp $http
delete_CkJsonObject $jsonToken
delete_CkJsonObject $jsonMetaData
delete_CkHttpResponse $resp
exit
}
set statusCode [CkHttpResponse_get_StatusCode $resp]
puts "response status code = $statusCode"
set sessionUrl ""
if {$statusCode != 200} then {
puts [CkHttpResponse_bodyStr $resp]
} else {
# The session URL will be used to upload the file in chunks, in subsequent HTTP POSTs...
set sessionUrl [CkHttpResponse_getHeaderField $resp "Location"]
puts "Session URL = $sessionUrl"
}
delete_CkHttp $http
delete_CkJsonObject $jsonToken
delete_CkJsonObject $jsonMetaData
delete_CkHttpResponse $resp