Amazon-S3

 view release on metacpan or  search on metacpan

lib/Amazon/S3/Bucket.pm  view on Meta::CPAN


      $fh->close  # otherwise, we found EOF
        or croak "close of upload content $filename failed: $OS_ERROR";

      $buffer ||= $EMPTY;  # LWP expects an empty string on finish, read returns 0
    }

    $remaining -= length $buffer;

    return $buffer;
  };
}

########################################################################
sub _create_multipart_upload_request {
########################################################################
  my ( $parts_hr, $algorithm ) = @_;

  my @parts;

  foreach my $part_num ( sort { $a <=> $b } keys %{$parts_hr} ) {
    my $part = $parts_hr->{$part_num};

    my $entry = { PartNumber => $part_num, };

    if ( ref $part ) {
      $entry->{ETag} = $part->{etag};

      if ( defined $part->{checksum} ) {
        my $checksum_name = 'Checksum' . uc $algorithm;

        $entry->{$checksum_name} = $part->{checksum};
      }
    }
    else {
      # Legacy part_number => etag representation
      $entry->{ETag} = $part;
    }

    push @parts, $entry;
  }

  return create_xml_request( { CompleteMultipartUpload => { Part => \@parts } } );
}

1;

__END__

=pod

=head1 NAME

Amazon::S3::Bucket - An Amazon S3 bucket and object interface

=head1 SYNOPSIS

  use Amazon::S3;

  my $s3 = Amazon::S3->new(
    { credentials => $credentials,
      region      => 'us-east-1',
    }
  );

  my $bucket = $s3->bucket('example-bucket');

  $bucket->add_key(
    'example.txt',
    'hello world',
    { content_type => 'text/plain',
    }
  );

  my $object = $bucket->get_key('example.txt');

  my $response = $bucket->list_v2(
    { prefix => 'logs/',
    }
  );

  $bucket->delete_key('example.txt');

=head1 DESCRIPTION

C<Amazon::S3::Bucket> represents an Amazon S3 bucket and provides
bucket-scoped object operations.

Instances are normally created by L<Amazon::S3/bucket> or
L<Amazon::S3/bucketv2> rather than by calling C<new()> directly.

This document is primarily a method reference. For broader discussion
of credentials, checksums, object listing, multipart uploads, error
handling, and directory buckets, see L<Amazon::S3>.

=head1 METHODS AND SUBROUTINES

=head2 CONSTRUCTOR

=head3 new

  my $bucket = Amazon::S3::Bucket->new(%options);

  my $bucket = Amazon::S3::Bucket->new(\%options);

Creates and returns a bucket object.

The constructor accepts either a list of key/value pairs or a hash
reference.

The following options are supported:

=over 4

=item account

Required. The L<Amazon::S3> object associated with this bucket.

=item bucket

Required. Bucket name.

=item buffer_size

Buffer size used when streaming object data.

The default is 4096 bytes.

=item logger

Logger used by the bucket object.

When omitted, the logger from C<account> is used.

=item region

Region containing the bucket.

When omitted and C<verify_region> is false, the region configured on
the associated L<Amazon::S3> object is used.

=item verify_region

When true and no region is supplied, determine the bucket region by
calling C<get_location_constraint()>.

The default is false.

=back

The constructor throws an exception when C<bucket> or C<account> is
not supplied.



( run in 1.577 second using v1.01-cache-2.11-cpan-3f962061493 )