Backblaze-B2V2Client
view release on metacpan or search on metacpan
lib/Backblaze/B2V2Client.pm view on Meta::CPAN
my ($bucket_name) = @_;
# bucket_name is required
if (!$bucket_name) {
$self->error_tracker('The bucket_name must be provided for b2_get_upload_url().');
return $self->{current_status};
}
# no need to proceed if we already have done for this bucket this during this session
# return if $self->{bucket_info}{$bucket_name}{upload_url};
# COMMENTED OUT: It seems like B2 wants a new upload_url endpoint for each upload,
# and we may want to upload multiple files into each bucket...so this won't work
# if we don't have the info for the bucket name, retrieve the bucket's ID
if (ref($self->{buckets}{$bucket_name}) ne 'HASH') {
$self->b2_list_buckets($bucket_name);
}
# send the request
$self->b2_talker(
'url' => $self->{api_url}.'/b2api/v2/b2_get_upload_url',
lib/Backblaze/B2V2Client.pm view on Meta::CPAN
# phew, i'm tired...
return $self->{current_status};
}
# generic method to handle communication to B2
sub b2_talker {
my $self = shift;
# args hash must include 'url' for the target API endpoint URL
# most other requests will also include a 'post_params' hashref, and 'authorization' value for the header
# for the b2_upload_file function, there will be several other headers + a file_contents arg
my (%args) = @_;
if (!$args{url}) {
$self->error_tracker('Can not use b2_talker() without an endpoint URL.');
}
# if they sent an Authorization header, set that value
if ($args{authorization}) {
$self->{mech}->delete_header( 'Authorization' );
$self->{mech}->add_header( 'Authorization' => $args{authorization} );
}
my ($response, $response_code, $error_message, $header, @header_keys);
( run in 1.068 second using v1.01-cache-2.11-cpan-49f99fa48dc )