![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C++) Initiate Resumable Upload SessionSee more Google Cloud Storage ExamplesInitiate a Google Cloud Storage resumable upload session..For more information, see https://cloud.google.com/storage/docs/performing-resumable-uploads
#include <CkHttpW.h> #include <CkJsonObjectW.h> #include <CkHttpResponseW.h> void ChilkatSample(void) { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttpW http; CkJsonObjectW jsonToken; bool 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 = http.PText(L"POST",url,jsonMetaData.emit(),L"utf-8",L"application/json",false,false); if (http.get_LastMethodSuccess() == 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); } delete resp; } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.