Tcl Google Cloud Storage: Delete a File (i.e. Object)

Back to Index

Deletes a fie (also known as an object) from a Google Cloud Storage bucket. The name of the bucket is specified in the URL's path. This example deletes the "starfish.jpg" object from the "chilkat-test" bucket. A successful DELETE is indicated by a 204 response status code with an empty response body.

Documentation: https://cloud.google.com/storage/docs/json_api/v1/objects/delete

CURL Command

curl -X DELETE https://www.googleapis.com/storage/v1/b/chilkat-bucket/o/starfish.jpg?project=MY_CLOUD_STORAGE_PROJECT \
    --header "Authorization: Bearer CLOUD_STORAGE_TOKEN"

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

#  URL: https://www.googleapis.com/storage/v1/b/chilkat-bucket/o/starfish.jpg?project=MY_CLOUD_STORAGE_PROJECT
set bTls 1
set port 443
set bAutoReconnect 1
set success [CkRest_Connect $rest "www.googleapis.com" $port $bTls $bAutoReconnect]
if {[expr $success != 1]} then {
    puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

CkRest_AddHeader $rest "Authorization" "Bearer CLOUD_STORAGE_TOKEN"

set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "DELETE" "/storage/v1/b/chilkat-bucket/o/starfish.jpg?project=MY_CLOUD_STORAGE_PROJECT" $sbResponseBody]
if {[expr $success != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkStringBuilder $sbResponseBody
    exit
}

set respStatusCode [CkRest_get_ResponseStatusCode $rest]
if {[expr $respStatusCode >= 400]} then {
    puts "Response Status Code = $respStatusCode"
    puts "Response Header:"
    puts [CkRest_responseHeader $rest]
    puts "Response Body:"
    puts [CkStringBuilder_getAsString $sbResponseBody]
    delete_CkRest $rest
    delete_CkStringBuilder $sbResponseBody
    exit
}


delete_CkRest $rest
delete_CkStringBuilder $sbResponseBody