Class: AWS::S3::Client

Inherits:
Core::Client show all
Extended by:
Validators
Includes:
Core::UriEscape, Validators, DataOptions
Defined in:
lib/aws/s3/client.rb,
lib/aws/s3/client/xml.rb

Overview

Client class for Amazon Simple Storage Service (S3).

Defined Under Namespace

Modules: Validators, XML

Constant Summary collapse

API_VERSION =
'2006-03-01'
XMLNS =
"http://s3.amazonaws.com/doc/#{API_VERSION}/"
EMPTY_BODY_ERRORS =
{
  304 => Errors::NotModified,
  404 => Errors::NoSuchKey
}
CACHEABLE_REQUESTS =
Set[]

Instance Attribute Summary

Attributes inherited from Core::Client

#config, #endpoint, #port, #service_ruby_name, #signer

Instance Method Summary collapse

Methods included from Validators

dns_compatible_bucket_name?, json_validation_message, path_style_bucket_name?, require_acl!, require_bucket_name!, require_policy!, require_upload_id!, valid_bucket_name?, validate!, validate_bucket_name!, validate_key!, validate_parts!, xml_validation_message

Methods included from Core::UriEscape

#escape, #escape_path

Methods inherited from Core::Client

#initialize, #new_stub_for, #operations, #stub_for, #with_config, #with_http_handler, #with_options

Methods included from Core::Naming

#service_name, #service_ruby_name

Constructor Details

This class inherits a constructor from AWS::Core::Client

Instance Method Details

#abort_multipart_upload(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :key (required, String)
  • :upload_id (required, String)

Returns:



847
848
849
850
851
852
853
# File 'lib/aws/s3/client.rb', line 847

object_method(:abort_multipart_upload, :delete) do
  configure_request do |req, options|
      require_upload_id!(options[:upload_id])
    super(req, options)
    req.add_param('uploadId', options[:upload_id])
  end
end

#complete_multipart_upload(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :key (required, String)
  • :upload_id (required, String)
  • :parts (required, Array<String>)

Returns:



813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
# File 'lib/aws/s3/client.rb', line 813

object_method(:complete_multipart_upload, :post,
              XML::CompleteMultipartUpload) do
  configure_request do |req, options|
    require_upload_id!(options[:upload_id])
    validate_parts!(options[:parts])
    super(req, options)
    req.add_param('uploadId', options[:upload_id])
    parts_xml = options[:parts].map do |part|
      "<Part>"+
        "<PartNumber>#{part[:part_number].to_i}</PartNumber>"+
        "<ETag>#{REXML::Text.normalize(part[:etag].to_s)}</ETag>"+
        "</Part>"
    end.join
    req.body =
      "<CompleteMultipartUpload>#{parts_xml}</CompleteMultipartUpload>"
  end

  process_response do |response|
    add_sse_to_response(response)
    response.data[:version_id] = 
      response.http_response.header('x-amz-version-id')
  end

  simulate_response do |response|
    response.data[:version_id] = nil
  end
end

#copy_object(options = {}) ⇒ Core::Response

Copies an object from one key to another.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)

    Name of the bucket to copy a object into.

  • :key (required, String)

    Where (object key) in the bucket the object should be copied to.

  • :copy_source (required, String)

    The source bucket name and key, joined by a forward slash (‘/’). This string must be URL-encoded. Additionally, you must have read access to the source object.

  • :acl (Symbol)

Returns:



888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
# File 'lib/aws/s3/client.rb', line 888

object_method(:copy_object, :put,
              :header_options => {
                :copy_source => 'x-amz-copy-source',
                :cache_control => 'Cache-Control',
                :metadata_directive => 'x-amz-metadata-directive',
                :storage_class => 'x-amz-storage-class',
                :server_side_encryption => 'x-amz-server-side-encryption',
                :content_type => 'Content-Type',
              }) do

  configure_request do |req, options|
    # TODO : validate metadata directive COPY / REPLACE
    # TODO : validate storage class STANDARD / REDUCED_REDUNDANCY
    # TODO : add validations for storage class in other places used
    validate!(:copy_source, options[:copy_source]) do
      "may not be blank" if options[:copy_source].to_s.empty?
    end
    options = options.merge(:copy_source => escape_path(options[:copy_source]))
    options[:server_side_encryption] =
      options[:server_side_encryption].to_s.upcase if
      options[:server_side_encryption].kind_of?(Symbol)
    super(req, options)
    req.canned_acl = options[:acl]
    req. = options[:metadata]
    req.storage_class = options[:storage_class]
    if options[:version_id]
      req.headers['x-amz-copy-source'] += "?versionId=#{options[:version_id]}"
    end
  end

  process_response do |response|
    response.data[:version_id] = 
      response.http_response.header('x-amz-version-id')
    response.data[:etag] = response.http_response.header('ETag')
    if time = response.http_response.header('Last-Modified')
      response.data[:last_modified] = Time.parse(time)
    end
    add_sse_to_response(response)
  end

end

#create_bucket(options = {}) ⇒ Core::Response

Creates a bucket.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)

Returns:



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/aws/s3/client.rb', line 112

bucket_method(:create_bucket, :put) do
  configure_request do |req, options|
    validate_bucket_name!(options[:bucket_name])
    req.canned_acl = options[:acl]
    if location = options[:location_constraint]
      xmlns = "http://s3.amazonaws.com/doc/#{API_VERSION}/"
      req.body = <<-XML
        <CreateBucketConfiguration xmlns="#{xmlns}">
          <LocationConstraint>#{location}</LocationConstraint> 
        </CreateBucketConfiguration>
      XML
    end
    super(req, options)
  end
end

#delete_bucket(options = {}) ⇒ Core::Response

Deletes an empty bucket.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)

Returns:



133
# File 'lib/aws/s3/client.rb', line 133

bucket_method(:delete_bucket, :delete)

#delete_bucket_lifecycle_configuration(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)

Returns:



175
176
177
178
179
180
181
182
# File 'lib/aws/s3/client.rb', line 175

bucket_method(:delete_bucket_lifecycle_configuration, :delete) do
  
  configure_request do |req, options|
    req.add_param('lifecycle')
    super(req, options)
  end

end

#delete_bucket_policy(options = {}) ⇒ Core::Response

Deletes the access policy for a bucket.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)

Returns:



240
# File 'lib/aws/s3/client.rb', line 240

bucket_method(:delete_bucket_policy, :delete, 'policy')

#delete_object(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :key (required, String)
  • :version_id (String)

Returns:



631
632
633
634
635
636
637
638
639
640
641
642
643
644
# File 'lib/aws/s3/client.rb', line 631

object_method(:delete_object, :delete) do

  configure_request do |req, options|
    super(req, options)
    if options[:version_id]
      req.add_param('versionId', options[:version_id])
    end
  end

  process_response do |resp|
    resp.data[:version_id] = resp.http_response.header('x-amz-version-id')
  end

end

#delete_objects(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :keys (required, Array<String>)
  • :quiet (Boolean) — default: true

Returns:



739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'lib/aws/s3/client.rb', line 739

bucket_method(:delete_objects, :post, 'delete', XML::DeleteObjects) do
  configure_request do |req, options|

    super(req, options)

    quiet = options.key?(:quiet) ? options[:quiet] : true

    # previously named this option :objects, since renamed
    keys = options[:objects] || options[:keys]

    objects = keys.inject('') do |xml,o|
      xml << "<Object><Key>#{o[:key]}</Key>"
      xml << "<VersionId>#{o[:version_id]}</VersionId>" if o[:version_id]
      xml << "</Object>"
    end

    xml = '<?xml version="1.0" encoding="UTF-8"?>'
    xml << "<Delete><Quiet>#{quiet}</Quiet>#{objects}</Delete>"

    req.body = xml

    md5 = Base64.encode64(Digest::MD5.digest(xml)).strip

    req.headers['content-md5'] = md5

  end
end

#get_bucket_acl(options = {}) ⇒ Core::Response

Gets the access control list for a bucket.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)

Returns:



342
# File 'lib/aws/s3/client.rb', line 342

bucket_method(:get_bucket_acl, :get, 'acl', XML::GetBucketAcl)

#get_bucket_lifecycle_configuration(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)

Returns:



157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/aws/s3/client.rb', line 157

bucket_method(:get_bucket_lifecycle_configuration, :get) do

  configure_request do |req, options|
    req.add_param('lifecycle')
    super(req, options)
  end

  process_response do |resp|
    xml = resp.http_response.body
    resp.data = XML::GetBucketLifecycleConfiguration.parse(xml)
  end

end

#get_bucket_location(options = {}) ⇒ Core::Response

Gets the bucket’s location constraint.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)

Returns:



269
270
271
272
273
274
275
276
277
# File 'lib/aws/s3/client.rb', line 269

bucket_method(:get_bucket_location, :get, 'location') do

  process_response do |response|
    regex = />(.*)<\/LocationConstraint>/
    matches = response.http_response.body.match(regex)
    response.data[:location_constraint] = matches ? matches[1] : nil
  end

end

#get_bucket_policy(options = {}) ⇒ Core::Response

Gets the access policy for a bucket.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)

Returns:



227
228
229
230
231
232
233
# File 'lib/aws/s3/client.rb', line 227

bucket_method(:get_bucket_policy, :get, 'policy') do

  process_response do |resp|
    resp.data[:policy] = resp.http_response.body
  end

end

#get_bucket_versioning(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)

Returns:



283
284
# File 'lib/aws/s3/client.rb', line 283

bucket_method(:get_bucket_versioning, :get, 'versioning',
XML::GetBucketVersioning)

#get_object(options = {}) ⇒ Core::Response

Gets the data for a key.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :key (required, String)
  • :if_modified_since (Time)

    If specified, the response will contain an additional :modified value that returns true if the object was modified after the given time. If :modified is false, then the response :data value will be nil.

  • :if_unmodified_since (Time)

    If specified, the response will contain an additional :unmodified value that is true if the object was not modified after the given time. If :unmodified returns false, the :data value will be nil.

  • :if_match (String)

    If specified, the response will contain an additional :matches value that is true if the object ETag matches the value for this option. If :matches is false, the :data value of the response will be nil.

  • :if_none_match (String)

    If specified, the response will contain an additional :matches value that is true if and only if the object ETag matches the value for this option. If :matches is true, the :data value of the response will be nil.

  • :range (Range<Integer>)

    A byte range of data to request.

Returns:



526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/aws/s3/client.rb', line 526

object_method(:get_object, :get,
              :header_options => {
                :if_modified_since => "If-Modified-Since",
                :if_unmodified_since => "If-Unmodified-Since",
                :if_match => "If-Match",
                :if_none_match => "If-None-Match"
              }) do
  configure_request do |req, options|

    super(req, options)

    if options[:version_id]
      req.add_param('versionId', options[:version_id])
    end

    ["If-Modified-Since",
     "If-Unmodified-Since"].each do |date_header|
      case value = req.headers[date_header]
      when DateTime
        req.headers[date_header] = Time.parse(value.to_s).rfc2822
      when Time
        req.headers[date_header] = value.rfc2822
      end
    end

    if options[:range]
      range = options[:range]
      range = "bytes=#{range.first}-#{range.last}" if range.is_a?(Range)
      req.headers['Range'] = range
    end

  end

  process_response do |resp|
    resp.data[:data] = resp.http_response.body
    resp.data[:version_id] = resp.http_response.header('x-amz-version-id')
    add_sse_to_response(resp)
  end
end

#get_object_acl(options = {}) ⇒ Core::Response

Gets the access control list for an object.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :key (required, String)

Returns:



378
# File 'lib/aws/s3/client.rb', line 378

object_method(:get_object_acl, :get, 'acl', XML::GetBucketAcl)

#head_object(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :key (required, String)
  • :version_id (String)

Returns:



572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
# File 'lib/aws/s3/client.rb', line 572

object_method(:head_object, :head) do

  configure_request do |req, options|
    super(req, options)
    if options[:version_id]
      req.add_param('versionId', options[:version_id])
    end
  end

  process_response do |resp|

    # create a hash of user-supplied metadata
    meta = {}
    resp.http_response.headers.each_pair do |name,value|
      if name =~ /^x-amz-meta-(.+)$/i
        meta[$1] = [value].flatten.join
      end
    end
    meta
    resp.data[:meta] = meta

    if expiry = resp.http_response.headers['x-amz-expiration']
      expiry.first =~ /^expiry-date="(.+)", rule-id="(.+)"$/
      exp_date = DateTime.parse($1)
      exp_rule_id = $2
    else
      exp_date = nil
      exp_rule_id = nil
    end

    resp.data[:expiration_date] = exp_date
    resp.data[:expiration_rule_id] = exp_rule_id

    {
      'x-amz-version-id' => :version_id,
      'content-type' => :content_type,
      'etag' => :etag,
    }.each_pair do |header,method|
      resp.data[method] = resp.http_response.header(header)
    end

    if time = resp.http_response.header('Last-Modified')
      resp.data[:last_modified] = Time.parse(time)
    end

    resp.data[:content_length] = 
      resp.http_response.header('content-length').to_i

    add_sse_to_response(resp)

  end
end

#initiate_multipart_upload(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :key (required, String)
  • :metadata (Hash)
  • :acl (Symbol)
  • :cache_control (String)
  • :content_disposition (String)
  • :content_encoding (String)
  • :content_type (String)
  • :storage_class (String)
  • :server_side_encryption (String)
  • :expires (String)

Returns:



682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
# File 'lib/aws/s3/client.rb', line 682

object_method(:initiate_multipart_upload, :post, 'uploads',
              XML::InitiateMultipartUpload,
              :header_options => {
                :cache_control => 'Cache-Control',
                :content_disposition => 'Content-Disposition',
                :content_encoding => 'Content-Encoding',
                :content_type => 'Content-Type',
                :storage_class => 'x-amz-storage-class',
                :server_side_encryption => 'x-amz-server-side-encryption',
                :expires => 'Expires'
              }) do
  configure_request do |req, options|
    options[:server_side_encryption] =
      options[:server_side_encryption].to_s.upcase if
      options[:server_side_encryption].kind_of?(Symbol)
    super(req, options)
    req. = options[:metadata]
    req.canned_acl = options[:acl]
    req.storage_class = options[:storage_class]
  end

  process_response do |response|
    add_sse_to_response(response)
  end
end

#list_buckets(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Returns:



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/aws/s3/client.rb', line 187

add_client_request_method(:list_buckets) do

  configure_request do |req, options|
    req.http_method = "GET"
  end

  process_response do |resp|
    resp.data = XML::ListBuckets.parse(resp.http_response.body)
  end

  simulate_response do |resp|
    resp.data = Core::XML::Parser.new(XML::ListBuckets.rules).simulate
  end

end

#list_multipart_uploads(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :delimiter (String)
  • :key_marker (String)
  • :max_keys (String)
  • :upload_id_marker (String)
  • :max_uploads (String)
  • :prefix (String)

Returns:



718
719
720
721
722
723
724
725
726
727
728
729
730
731
# File 'lib/aws/s3/client.rb', line 718

bucket_method(:list_multipart_uploads,
              :get, 'uploads',
              XML::ListMultipartUploads) do
  configure_request do |req, options|
    super(req, options)
    params = %w(delimiter key_marker max_keys) +
      %w(upload_id_marker max_uploads prefix)
    params.each do |param|
      if options[param.to_sym]
        req.add_param(param.gsub(/_/, '-'), options[param.to_sym])
      end
    end
  end
end

#list_object_versions(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :prefix (String)
  • :delimiter (String)
  • :max_keys (String)
  • :key_marker (String)
  • :version_id_marker (String)

Returns:



295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/aws/s3/client.rb', line 295

bucket_method(:list_object_versions, :get, 'versions',
  XML::ListObjectVersions) do

  configure_request do |req, options|
    super(req, options)
    params = %w(delimiter key_marker max_keys prefix version_id_marker)
    params.each do |param|
      if options[param.to_sym]
        req.add_param(param.gsub(/_/, '-'), options[param.to_sym])
      end
    end
  end

end

#list_objects(options = {}) ⇒ Core::Response Also known as: get_bucket

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :delimiter (String)
  • :marker (String)
  • :max_keys (String)
  • :prefix (String)

Returns:



654
655
656
657
658
659
660
661
662
663
664
# File 'lib/aws/s3/client.rb', line 654

bucket_method(:list_objects, :get, XML::ListObjects) do
  configure_request do |req, options|
    super(req, options)
    params = %w(delimiter marker max_keys prefix)
    params.each do |param|
      if options[param.to_sym]
        req.add_param(param.gsub(/_/, '-'), options[param.to_sym])
      end
    end
  end
end

#list_parts(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :key (required, String)
  • :upload_id (required, String)
  • :max_parts (Integer)
  • :part_number_marker (Integer)

Returns:



863
864
865
866
867
868
869
870
871
872
873
# File 'lib/aws/s3/client.rb', line 863

object_method(:list_parts, :get, XML::ListParts) do

  configure_request do |req, options|
      require_upload_id!(options[:upload_id])
    super(req, options)
    req.add_param('uploadId', options[:upload_id])
    req.add_param('max-parts', options[:max_parts])
    req.add_param('part-number-marker', options[:part_number_marker])
  end

end

#put_object(options = {}) ⇒ Core::Response

Puts data into an object, replacing the current contents.

s3_client.put_object({
  :bucket_name => 'bucket-name',
  :key => 'readme.txt', 
  :data => 'This is the readme for ...',
})

Block Form

In block form, this method yields a stream to the block that accepts data chunks. For example:

s3_client.put_object(
  :bucket_name => 'mybucket', 
  :key => 'some/key'
  :content_length => File.size('myfile')
) do |buffer|

  File.open('myfile') do |io| 
    buffer.write(io.read(length)) until io.eof?
  end

end

This form is useful if you need finer control over how potentially large amounts of data are read from another source before being sent to S3; for example, if you are using a non-blocking IO model and reading from a large file on disk or from another network stream. Some HTTP handlers do not support streaming request bodies, so if you plan to upload large objects using this interface you should make sure the HTTP handler you configure for the client meets your needs.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :key (required, String)
  • :data (required, String, Pathname, File, IO)

    The data to upload. This can be provided as a string, a Pathname object, or any object that responds to #read and #eof? (e.g. IO, File, Tempfile, StringIO, etc).

  • :content_length (Integer)

    Required if you are using block form to write data or if it is not possible to determine the size of :data. A best effort is made to determine the content length of strings, files, tempfiles, io objects, and any object that responds to #length or #size.

  • :metadata (Hash)

    A hash of metadata to be included with the object. These will be sent to S3 as headers prefixed with x-amz-meta.

  • :acl (Symbol) — default: :private

    A canned access control policy. Accepted values include:

    • :private

    • :public_read

  • :storage_class+ (Symbol) — default: :standard

    Controls whether Reduced Redundancy Storage is enabled for the object. Valid values are :standard and :reduced_redundancy.

  • :cache_control (String)

    Can be used to specify caching behavior.

  • :content_encoding (String)

    Specifies the content encoding.

  • :content_md5 (String)

    The base64 encoded content md5 of the :data.

  • :content_type (String)

    Specifies the content type.

  • :expires (String)

Returns:



455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File 'lib/aws/s3/client.rb', line 455

object_method(:put_object, :put,
              :header_options => {
                :content_md5 => 'Content-MD5',
                :cache_control => 'Cache-Control',
                :content_disposition => 'Content-Disposition',
                :content_encoding => 'Content-Encoding',
                :content_type => 'Content-Type',
                :storage_class => 'x-amz-storage-class',
                :server_side_encryption => 'x-amz-server-side-encryption',
                :expires => 'Expires'
              }) do
  configure_request do |request, options, block|
    options[:server_side_encryption] =
      options[:server_side_encryption].to_s.upcase if
      options[:server_side_encryption].kind_of?(Symbol)
    super(request, options)
    set_request_data(request, options, block)
    request. = options[:metadata]
    request.canned_acl = options[:acl]
    request.storage_class = options[:storage_class]
  end

  process_response do |response|

    response.data[:version_id] = 
      response.http_response.header('x-amz-version-id')

    response.data[:etag] = response.http_response.header('ETag')

    if time = response.http_response.header('Last-Modified')
      response.data[:last_modified] = Time.parse(time)
    end

    add_sse_to_response(response)
  end

  simulate_response do |response|
    response.data[:etag] = 'abc123'
    response.data[:version_id] = nil
  end

end

#set_bucket_acl(options = {}) ⇒ Core::Response

Sets the access control list for a bucket.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :acl (required, String, AccessControlList, Hash)

    This may be any of the following:

    • An XML policy as a string (which is passed to S3 uninterpreted)

    • An AccessControlList object

    • Any object that responds to #to_xml

    • A hash that is compatible with AccessControlList #new.

Returns:



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/aws/s3/client.rb', line 321

bucket_method(:set_bucket_acl, :put, 'acl') do

  configure_request do |req, options|
      require_acl!(options[:acl])
    super(req, options)
    if options[:acl].kind_of?(Hash)
      req.body = AccessControlList.new(options[:acl]).to_xml
    elsif options[:acl].respond_to?(:to_str)
      req.body = options[:acl]
    else
      req.body = options[:acl].to_xml
    end
  end

end

#set_bucket_lifecycle_configuration(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :lifecycle_configuration (required, String)

Returns:



140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/aws/s3/client.rb', line 140

bucket_method(:set_bucket_lifecycle_configuration, :put) do

  configure_request do |req, options|
    xml = options[:lifecycle_configuration]
    md5 = Base64.encode64(Digest::MD5.digest(xml)).strip
    req.add_param('lifecycle')
    req.body = xml
    req.headers['content-md5'] = md5
    super(req, options)
  end

end

#set_bucket_policy(options = {}) ⇒ Core::Response

Sets the access policy for a bucket.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :policy (required, String)

    This can be a String or any object that responds to #to_json.

Returns:



210
211
212
213
214
215
216
217
218
219
220
# File 'lib/aws/s3/client.rb', line 210

bucket_method(:set_bucket_policy, :put, 'policy') do

  configure_request do |req, options|
    require_policy!(options[:policy])
    super(req, options)
    policy = options[:policy]
    policy = policy.to_json unless policy.respond_to?(:to_str)
    req.body = policy
  end

end

#set_bucket_versioning(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :state (required, String)

Returns:



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/aws/s3/client.rb', line 247

bucket_method(:set_bucket_versioning, :put, 'versioning') do

  configure_request do |req, options|
    state = options[:state].to_s.downcase.capitalize
    unless state =~ /^(Enabled|Suspended)$/
      raise ArgumentError, "invalid versioning state `#{state}`"
    end
    super(req, options)
    req.body = <<-XML.strip
      <VersioningConfiguration xmlns="#{XMLNS}">
        <Status>#{state}</Status>
      </VersioningConfiguration>
    XML
  end

end

#set_object_acl(options = {}) ⇒ Core::Response

Sets the access control list for an object.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :key (required, String)
  • :acl (required, String, AccessControlList, Hash)

    This may be any of the following:

    • An XML policy as a string (which is passed to S3 uninterpreted)

    • An AccessControlList object

    • Any object that responds to #to_xml

    • A hash that is compatible with AccessControlList #new.

Returns:



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/aws/s3/client.rb', line 356

object_method(:set_object_acl, :put, 'acl') do
  configure_request do |req, options|
    require_acl!(options[:acl]) unless options[:acl].kind_of?(Symbol)
    super(req, options)
    if options[:acl].kind_of?(Hash)
      req.body = AccessControlList.new(options[:acl]).to_xml
    elsif options[:acl].kind_of?(Symbol)
      req.headers["x-amz-acl"] = options[:acl].to_s.tr("_","-")
    elsif options[:acl].respond_to?(:to_str)
      req.body = options[:acl]
    else
      req.body = options[:acl].to_xml
    end
  end
end

#upload_part(options = {}) ⇒ Core::Response

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :bucket_name (required, String)
  • :key (required, String)
  • :data (required, String, Pathname, File, IO)

    The data to upload. This can be provided as a string, a Pathname object, or any object that responds to #read and #eof? (e.g. IO, File, Tempfile, StringIO, etc).

  • :upload_id (required, String)
  • :part_number (required, Integer)

Returns:



778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
# File 'lib/aws/s3/client.rb', line 778

object_method(:upload_part, :put,
              :header_options => {
                :content_md5 => 'Content-MD5'
              }) do
  configure_request do |request, options, block|
      require_upload_id!(options[:upload_id])
    validate!("part_number", options[:part_number]) do
      "must not be blank" if options[:part_number].to_s.empty?
    end
    super(request, options)
    set_request_data(request, options, block)
    request.add_param('uploadId', options[:upload_id])
    request.add_param('partNumber', options[:part_number])
  end

  process_response do |response|
    response.data[:etag] = response.http_response.header('ETag')
    if time = response.http_response.header('Last-Modified')
      response.data[:last_modified] = Time.parse(time)
    end
    add_sse_to_response(response)
  end

  simulate_response do |response|
    response.data[:etag] = 'abc123'
  end
end