The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

->request

Returns a promise that will resolve to the response data and the headers from the request.

->json_request

my $res = $b2->json_request(...)->then(sub {
    my( $ok, $message, @stuff ) = @_;
});

Helper routine that expects a JSON formatted response and returns the decoded JSON structure.

$b2->create_bucket

$b2->create_bucket(
    bucketName => 'my_files',
    bucketType => 'allPrivate',
);

Bucket names can consist of: letters, digits, "-", and "_".

https://www.backblaze.com/b2/docs/b2_create_bucket.html

The bucketName has to be globally unique, so expect this request to fail, a lot.

$b2->delete_bucket

$b2->delete_bucket(
    bucketId => ...,
);

Bucket names can consist of: letters, digits, "-", and "_".

https://www.backblaze.com/b2/docs/b2_delete_bucket.html

The bucket must be empty of all versions of all files.

$b2->list_buckets

$b2->list_buckets();

https://www.backblaze.com/b2/docs/b2_list_buckets.html

Returns the error status, the message and the payload.

$b2->get_upload_url

my $upload_handle = $b2->get_upload_url();
$b2->upload_file( file => $file, handle => $upload_handle );

https://www.backblaze.com/b2/docs/b2_get_upload_url.html

$b2->upload_file

my $upload_handle = $b2->get_upload_url();
$b2->upload_file(
    file => $file,
    handle => $upload_handle
);

https://www.backblaze.com/b2/docs/b2_upload_file.html

Note: This method loads the complete file to be uploaded into memory.

Note: The Backblaze B2 API is vague about when you need a new upload URL.

$b2->list_file_names

my $startFileName;
my $list = $b2->list_file_names(
    startFileName => $startFileName,
    maxFileCount => 1000, # maximum per round
    bucketId => ...,
    
);

https://www.backblaze.com/b2/docs/b2_list_file_names.html

$b2->list_all_file_names

my $list = $b2->list_all_file_names(
    startFileName => $startFileName,
    maxFileCount => 1000, # maximum per round
    bucketId => ...,
    
);

Retrieves all filenames in a bucket

$b2->download_file_by_name

my $content = $b2->download_file_by_name(
    bucketName => $my_bucket_name,
    fileName => $my_file_name,
);

https://www.backblaze.com/b2/docs/b2_download_file_by_name.html

$b2->get_download_authorization

my $content = $b2->get_download_authorization(
    bucketId => $my_bucket_id,
    fileNamePrefix => $my_file_name,
    validDurationInSeconds => 300, # you have five minutes to start the download
);

https://www.backblaze.com/b2/docs/b2_get_download_authorization.html