Sample code for 30+ languages & platforms
Node.js

Initiate Resumable Upload Session

See more Google Cloud Storage Examples

Initiate a Google Cloud Storage resumable upload session..

Chilkat Node.js Downloads

Node.js
NODEJS_PRELUDE

function chilkatExample() {

    var success = false;

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

    var http = new chilkat.Http();

    var jsonToken = new chilkat.JsonObject();
    success = jsonToken.LoadFile("qa_data/tokens/googleCloudStorage.json");
    if (success == false) {
        console.log(jsonToken.LastErrorText);
        return;
    }

    var jsonMetaData = new chilkat.JsonObject();
    jsonMetaData.UpdateString("contentType","image/jpeg");

    // Adds the "Authorization: Bearer <access_token>" header..
    http.AuthToken = jsonToken.StringOf("access_token");

    http.SetUrlVar("bucket_name","chilkat-bucket-b");
    http.SetUrlVar("object_name","penguins2.jpg");
    var url = "https://storage.googleapis.com/upload/storage/v1/b/{$bucket_name}/o?uploadType=resumable&name={$object_name}";
    var resp = new chilkat.HttpResponse();
    success = http.HttpJson("POST",url,jsonMetaData,"application/json",resp);
    if (success == false) {
        console.log(http.LastErrorText);
        return;
    }

    var statusCode = resp.StatusCode;
    console.log("response status code = " + statusCode);

    var sessionUrl = "";

    if (statusCode !== 200) {
        console.log(resp.BodyStr);
    }
    else {
        // The session URL will be used to upload the file in chunks, in subsequent HTTP POSTs...
        sessionUrl = resp.GetHeaderField("Location");
        console.log("Session URL = " + sessionUrl);
    }


}

chilkatExample();