Class: Aws::S3::Bucket

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-resources/services/s3/bucket.rb

Instance Method Summary collapse

Instance Method Details

#clear!void

This method returns an undefined value.

Deletes all objects and versioned objects from this bucket

Examples:


bucket.clear!


14
15
16
# File 'lib/aws-sdk-resources/services/s3/bucket.rb', line 14

def clear!
  object_versions.batch_delete!
end

#delete!(options = { }) ⇒ void

This method returns an undefined value.

Deletes all objects and versioned objects from this bucket and then deletes the bucket.

Examples:


bucket.delete!

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :max_attempts (Integer) — default: 3

    Maximum number of times to attempt to delete the empty bucket before raising ‘Aws::S3::Errors::BucketNotEmpty`.

  • :initial_wait (Float) — default: 1.3

    Seconds to wait before retrying the call to delete the bucket, exponentially increased for each attempt.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/aws-sdk-resources/services/s3/bucket.rb', line 34

def delete! options = { }
  options = {
    initial_wait: 1.3,
    max_attempts: 3,
  }.merge(options)

  attempts = 0
  begin
    clear!
    delete
  rescue Errors::BucketNotEmpty
    attempts += 1
    if attempts >= options[:max_attempts]
      raise
    else
      Kernel.sleep(options[:initial_wait] ** attempts)
      retry
    end
  end
end

#loadObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



101
102
103
104
105
# File 'lib/aws-sdk-resources/services/s3/bucket.rb', line 101

def load
  @data = client.list_buckets.buckets.find { |b| b.name == name }
  raise "unable to load bucket #{name}" if @data.nil?
  self
end

#presigned_post(options = {}) ⇒ PresignedPost

Note:

You must specify ‘:key` or `:key_starts_with`. All other options are optional.

Creates a PresignedPost that makes it easy to upload a file from a web browser direct to Amazon S3 using an HTML post form with a file field.

See the PresignedPost documentation for more information.

Options Hash (options):

Returns:

See Also:



91
92
93
94
95
96
97
98
# File 'lib/aws-sdk-resources/services/s3/bucket.rb', line 91

def presigned_post(options = {})
  PresignedPost.new(
    client.config.credentials,
    client.config.region,
    name,
    {url: url}.merge(options)
  )
end

#url(options = {}) ⇒ String

Returns a public URL for this bucket.

bucket = s3.bucket('bucket-name')
bucket.url
#=> "https://bucket-name.s3.amazonaws.com"

You can pass ‘virtual_host: true` to use the bucket name as the host name.

bucket = s3.bucket('my.bucket.com', virtual_host: true)
bucket.url
#=> "http://my.bucket.com"

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :virtual_host (Boolean) — default: false

    When ‘true`, the bucket name will be used as the host name. This is useful when you have a CNAME configured for this bucket.

Returns:

  • (String)

    the URL for this bucket.



73
74
75
76
77
78
79
# File 'lib/aws-sdk-resources/services/s3/bucket.rb', line 73

def url(options = {})
  if options[:virtual_host]
    "http://#{name}"
  else
    s3_bucket_url
  end
end