Backblaze-B2V4
view release on metacpan or search on metacpan
[](https://github.com/ericschernoff/backblaze-b2v4/actions?workflow=test)
# NAME
Backblaze::B2V4 - Client library for the Backblaze B2 Cloud Storage Service V4 API.
# SYNOPSIS
use Backblaze::B2V4;
# create an API client object
my $b2 = Backblaze::B2V4->new(
application_key => $application_key,
application_key_id => $application_key_id,
);
# please encrypt/protect those keys when not in use!
# let's say we have a B2 bucket called 'GingerAnna' and a JPG called 'ginger_was_perfect.jpg'.
# upload a file from your file system
my $response = $b2->b2_upload_file(
bucket_name => 'GingerAnna',
file_location => '/path/to/ginger_was_perfect.jpg'
);
# upload a file you have in a scalar
my $response = $b2->b2_upload_file(
bucket_name => 'GingerAnna',
new_file_name => 'ginger_was_perfect.jpg',
file_contents => $file_contents
);
# B2 file ID (fGUID) is now in $response->{fileId}
# Best to load $file_contents via Path::Tiny's slurp_raw() method
# download that file to /opt/majestica/tmp
my $response = $b2->b2_download_file_by_name(
bucket_name => 'GingerAnna',
file_name => 'ginger_was_perfect.jpg',
save_to_location => '/opt/majestica/tmp'
);
# if you would rather download with the 84-character GUID
my $response = $b2->b2_download_file_by_id(
file_id => 'X-Bz-File-Id GUID from above',
save_to_location => '/opt/majestica/tmp'
);
# For all of these $response is the output from the B2 V4 API
# to confirm all is well
my $all_is_well = $b2->current_status_is_not_ok != 1;
# or
my $all_is_well = $b2->current_status_is_ok());
# to get the latest error
print $b2->latest_error();
# if none, will be 'No error message found'
# DESCRIPTION / SET UP
This module should help you create buckets and store/retrieve files in the
Backblaze B2 cloud storage service using V4 of their API.
Backblaze makes it easy to sign up for B2 from here:
https://www.backblaze.com/b2/sign-up.html
Then enable the B2 service as per these instructions:
https://www.backblaze.com/b2/docs/quick_account.html
Next, visit the 'App Keys' section of the 'My Account' area, and look for
the 'Add a New Application Key' button to create an application key. You
will need a key with Read and Write access. Be sure to note the Application Key
ID as well as the Application Key itself. They do not show you that Application
Key again, so copy it immediately.
Please store the Application Key pair in a secure way, preferably encrypted
when not in use by your software.
## b2\_client Command Line Utility
Backblaze::B2V4 includes the 'b2\_client' command line utility to
easily download or upload files from B2. Please execute 'b2\_client help'
for more details, and here are a few examples:
# download a file to current directory
b2_client get MyPictures FamilyPhoto.jpg
# download a file to a target directory
b2_client get MyPictures FamilyPhoto.jpg /home/ginger/photos
# upload a file to B2
b2_client put MyPictures /home/ginger/photos/AnotherFamilyPhoto.jpg
There is also an official command line utility from Backblaze that does a
whole lot more:
https://www.backblaze.com/b2/docs/quick_command_line.html
## BackBlaze B2 also has a S3-compatible API
Backblaze has added an S3-compatible API, which you can read about here:
https://www.backblaze.com/b2/docs/s3_compatible_api.html
They are continuing to support their native B2 API, so I will continue
to use and support this module. I have not tested the S3 modules with
Backblaze, but if you already have an S3 integration, it is worth
checking out how Paws::S3 or Awes::S3 works with Backblaze.
( run in 0.699 second using v1.01-cache-2.11-cpan-7fcb06a456a )