(JavaScript) Initiate Resumable Upload Session
Initiate a Google Cloud Storage resumable upload session..For more information, see https://cloud.google.com/storage/docs/performing-resumable-uploads
var success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var http = new CkHttp();
var jsonToken = new CkJsonObject();
success = jsonToken.LoadFile("qa_data/tokens/googleCloudStorage.json");
if (success == false) {
console.log(jsonToken.LastErrorText);
return;
}
var jsonMetaData = new CkJsonObject();
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 CkHttpResponse();
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);
}
|