Sample code for 30+ languages & platforms
Unicode C++

Initiate Resumable Upload Session

See more Google Cloud Storage Examples

Initiate a Google Cloud Storage resumable upload session..

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttpW http;

    CkJsonObjectW jsonToken;
    success = jsonToken.LoadFile(L"qa_data/tokens/googleCloudStorage.json");
    if (success == false) {
        wprintf(L"%s\n",jsonToken.lastErrorText());
        return;
    }

    CkJsonObjectW jsonMetaData;
    jsonMetaData.UpdateString(L"contentType",L"image/jpeg");

    // Adds the "Authorization: Bearer <access_token>" header..
    http.put_AuthToken(jsonToken.stringOf(L"access_token"));

    http.SetUrlVar(L"bucket_name",L"chilkat-bucket-b");
    http.SetUrlVar(L"object_name",L"penguins2.jpg");
    const wchar_t *url = L"https://storage.googleapis.com/upload/storage/v1/b/{$bucket_name}/o?uploadType=resumable&name={$object_name}";
    CkHttpResponseW resp;
    success = http.HttpJson(L"POST",url,jsonMetaData,L"application/json",resp);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    int statusCode = resp.get_StatusCode();
    wprintf(L"response status code = %d\n",statusCode);

    const wchar_t *sessionUrl = L"";

    if (statusCode != 200) {
        wprintf(L"%s\n",resp.bodyStr());
    }
    else {
        // The session URL will be used to upload the file in chunks, in subsequent HTTP POSTs...
        sessionUrl = resp.getHeaderField(L"Location");
        wprintf(L"Session URL = %s\n",sessionUrl);
    }
    }