Sample code for 30+ languages & platforms
Perl

Initiate Resumable Upload Session

See more Google Cloud Storage Examples

Initiate a Google Cloud Storage resumable upload session..

Chilkat Perl Downloads

Perl
use strict;
use warnings;
use Chilkat2;

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

my $http = Chilkat2::Http->new;

my $jsonToken = Chilkat2::JsonObject->new;
my $success = $jsonToken->LoadFile('qa_data/tokens/googleCloudStorage.json');
if (!$success) {
    print $jsonToken->LastErrorText, "\n";
    exit;
}

my $jsonMetaData = Chilkat2::JsonObject->new;
$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');
my $url = 'https://storage.googleapis.com/upload/storage/v1/b/{$bucket_name}/o?uploadType=resumable&name={$object_name}';
my $resp = Chilkat2::HttpResponse->new;
$success = $http->HttpJson('POST', $url, $jsonMetaData, 'application/json', $resp);
if (!$success) {
    print $http->LastErrorText, "\n";
    exit;
}

my $statusCode = $resp->StatusCode;
print 'response status code = ', $statusCode, "\n";

my $sessionUrl = '';

if ($statusCode != 200) {
    print $resp->BodyStr, "\n";
} else {
    # The session URL will be used to upload the file in chunks, in subsequent HTTP POSTs...
    $sessionUrl = $resp->GetHeaderField('Location');
    print 'Session URL = ', $sessionUrl, "\n";
}