Class: Aws::S3::ObjectSummary

Inherits:
Object
  • Object
show all
Extended by:
Deprecations
Defined in:
sig/object_summary.rbs,
lib/aws-sdk-s3/object_summary.rb,
lib/aws-sdk-s3/customizations/object_summary.rb,
sig/customizations/object_summary.rbs

Overview

Defined Under Namespace

Classes: Collection

Read-Only Attributes collapse

Actions collapse

Associations collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket_name, key, options) ⇒ void #initialize(bucket_name:, key:, client:) ⇒ void #initialize(args) ⇒ void

Overloads:

  • #initialize(bucket_name, key, options) ⇒ void

    Parameters:

    • bucket_name (String)
    • key (String)
    • options (Hash[Symbol, untyped])
  • #initialize(bucket_name:, key:, client:) ⇒ void

    Parameters:

    • bucket_name: (String)
    • key: (String)
    • client: (Client)
  • #initialize(args) ⇒ void

    Parameters:

    • args (Hash[Symbol, untyped])


24
25
26
27
28
29
30
31
# File 'lib/aws-sdk-s3/object_summary.rb', line 24

def initialize(*args)
  options = Hash === args.last ? args.pop.dup : {}
  @bucket_name = extract_bucket_name(args, options)
  @key = extract_key(args, options)
  @data = options.delete(:data)
  @client = options.delete(:client) || Client.new(options)
  @waiter_block_warned = false
end

Instance Method Details

#aclObjectAcl

Returns:



2930
2931
2932
2933
2934
2935
2936
# File 'lib/aws-sdk-s3/object_summary.rb', line 2930

def acl
  ObjectAcl.new(
    bucket_name: @bucket_name,
    object_key: @key,
    client: @client
  )
end

#bucketBucket

Returns:



2939
2940
2941
2942
2943
2944
# File 'lib/aws-sdk-s3/object_summary.rb', line 2939

def bucket
  Bucket.new(
    name: @bucket_name,
    client: @client
  )
end

#bucket_nameString

Returns:

  • (String)


36
37
38
# File 'lib/aws-sdk-s3/object_summary.rb', line 36

def bucket_name
  @bucket_name
end

#checksum_algorithm::Array[("CRC32" | "CRC32C" | "SHA1" | "SHA256" | "CRC64NVME" | "SHA512" | "MD5" | "XXHASH64" | "XXHASH3" | "XXHASH128")]

Returns:

  • (::Array[("CRC32" | "CRC32C" | "SHA1" | "SHA256" | "CRC64NVME" | "SHA512" | "MD5" | "XXHASH64" | "XXHASH3" | "XXHASH128")])


83
84
85
# File 'lib/aws-sdk-s3/object_summary.rb', line 83

def checksum_algorithm
  data[:checksum_algorithm]
end

#checksum_type"COMPOSITE", "FULL_OBJECT"

Returns:

  • ("COMPOSITE", "FULL_OBJECT")


95
96
97
# File 'lib/aws-sdk-s3/object_summary.rb', line 95

def checksum_type
  data[:checksum_type]
end

#clientClient

Returns:



153
154
155
# File 'lib/aws-sdk-s3/object_summary.rb', line 153

def client
  @client
end

#copy_from(source, options) ⇒ void #copy_fromvoid

Overloads:

  • #copy_from(source, options) ⇒ void

    This method returns an undefined value.

    Parameters:

    • source (Object)
    • options (Hash[Symbol, untyped])
  • #copy_fromvoid

    This method returns an undefined value.



1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
# File 'lib/aws-sdk-s3/object_summary.rb', line 1134

def copy_from(options = {})
  options = options.merge(
    bucket: @bucket_name,
    key: @key
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.copy_object(options)
  end
  resp.data
end

#copy_to(target, options = {}) ⇒ void

Parameters:

  • target (Object)
  • options (Hash[Symbol, untyped]) (defaults to: {})


24
25
26
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 24

def copy_to(target, options = {})
  object.copy_to(target, options)
end

#dataTypes::Object

Returns:



168
169
170
171
# File 'lib/aws-sdk-s3/object_summary.rb', line 168

def data
  load unless @data
  @data
end

#data_loaded?Boolean

Returns:

  • (Boolean)


176
177
178
# File 'lib/aws-sdk-s3/object_summary.rb', line 176

def data_loaded?
  !!@data
end

#delete(options = {}) ⇒ Object



1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
# File 'lib/aws-sdk-s3/object_summary.rb', line 1241

def delete(options = {})
  options = options.merge(
    bucket: @bucket_name,
    key: @key
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.delete_object(options)
  end
  resp.data
end

#download_file(destination, options = {}) ⇒ Boolean

Parameters:

  • destination (String)
  • options (Hash[Symbol, untyped]) (defaults to: {})

Returns:

  • (Boolean)


79
80
81
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 79

def download_file(destination, options = {})
  object.download_file(destination, options)
end

#etag::String

Returns:

  • (::String)


77
78
79
# File 'lib/aws-sdk-s3/object_summary.rb', line 77

def etag
  data[:etag]
end

#exists?(max_attempts:, delay:, before_attempt:, before_wait:) ⇒ Boolean #exists?(arg0) ⇒ Boolean

Overloads:

  • #exists?(max_attempts:, delay:, before_attempt:, before_wait:) ⇒ Boolean

    Parameters:

    • max_attempts: (Integer)
    • delay: (Numeric)
    • before_attempt: (^(Integer attempts) -)

      void]

    • before_wait: (^(Integer attempts, untyped response) -)

      void]

    Returns:

    • (Boolean)
  • #exists?(arg0) ⇒ Boolean

    Parameters:

    • arg0 (Hash[Symbol, untyped])

    Returns:

    • (Boolean)


183
184
185
186
187
188
189
190
191
192
# File 'lib/aws-sdk-s3/object_summary.rb', line 183

def exists?(options = {})
  begin
    wait_until_exists(options.merge(max_attempts: 1))
    true
  rescue Aws::Waiters::Errors::UnexpectedError => e
    raise e.error
  rescue Aws::Waiters::Errors::WaiterFailed
    false
  end
end

#get(options = {}, &block) ⇒ Object



1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
# File 'lib/aws-sdk-s3/object_summary.rb', line 1497

def get(options = {}, &block)
  options = options.merge(
    bucket: @bucket_name,
    key: @key
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.get_object(options, &block)
  end
  resp.data
end

#identifiersObject

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.

Deprecated.


2979
2980
2981
2982
2983
2984
# File 'lib/aws-sdk-s3/object_summary.rb', line 2979

def identifiers
  {
    bucket_name: @bucket_name,
    key: @key
  }
end

#initiate_multipart_upload(options = {}) ⇒ Object



2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
# File 'lib/aws-sdk-s3/object_summary.rb', line 2081

def initiate_multipart_upload(options = {})
  options = options.merge(
    bucket: @bucket_name,
    key: @key
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.create_multipart_upload(options)
  end
  MultipartUpload.new(
    bucket_name: @bucket_name,
    object_key: @key,
    id: resp.data.upload_id,
    client: @client
  )
end

#keyString

Returns:

  • (String)


41
42
43
# File 'lib/aws-sdk-s3/object_summary.rb', line 41

def key
  @key
end

#last_modified::Time

Returns:

  • (::Time)


47
48
49
# File 'lib/aws-sdk-s3/object_summary.rb', line 47

def last_modified
  data[:last_modified]
end

#loadObject Also known as: reload

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.

Raises:

  • (NotImplementedError)


159
160
161
162
# File 'lib/aws-sdk-s3/object_summary.rb', line 159

def load
  msg = "#load is not implemented, data only available via enumeration"
  raise NotImplementedError, msg
end

#move_to(target, options = {}) ⇒ void

Parameters:

  • target (Object)
  • options (Hash[Symbol, untyped]) (defaults to: {})


32
33
34
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 32

def move_to(target, options = {})
  object.move_to(target, options)
end

#multipart_upload(id) ⇒ MultipartUpload

Parameters:

  • id (String)

Returns:



2948
2949
2950
2951
2952
2953
2954
2955
# File 'lib/aws-sdk-s3/object_summary.rb', line 2948

def multipart_upload(id)
  MultipartUpload.new(
    bucket_name: @bucket_name,
    object_key: @key,
    id: id,
    client: @client
  )
end

#objectObject

Returns:



2958
2959
2960
2961
2962
2963
2964
# File 'lib/aws-sdk-s3/object_summary.rb', line 2958

def object
  Object.new(
    bucket_name: @bucket_name,
    key: @key,
    client: @client
  )
end

#ownerTypes::Owner

Returns:



125
126
127
# File 'lib/aws-sdk-s3/object_summary.rb', line 125

def owner
  data[:owner]
end

#presigned_post(options = {}) ⇒ Object

Parameters:

  • (Hash[Symbol, untyped])

Returns:



40
41
42
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 40

def presigned_post(options = {})
  object.presigned_post(options)
end

#presigned_url(http_method, params = {}) ⇒ String

Parameters:

  • method (Symbol, String)
  • params (Hash[Symbol, untyped]) (defaults to: {})

Returns:

  • (String)


48
49
50
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 48

def presigned_url(http_method, params = {})
  object.presigned_url(http_method, params)
end

#public_url(options = {}) ⇒ String

Parameters:

  • options (Hash[Symbol, untyped]) (defaults to: {})

Returns:

  • (String)


56
57
58
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 56

def public_url(options = {})
  object.public_url(options)
end

#put(options = {}) ⇒ Object



2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
# File 'lib/aws-sdk-s3/object_summary.rb', line 2775

def put(options = {})
  options = options.merge(
    bucket: @bucket_name,
    key: @key
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.put_object(options)
  end
  resp.data
end

#restore_object(options = {}) ⇒ Object



2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
# File 'lib/aws-sdk-s3/object_summary.rb', line 2916

def restore_object(options = {})
  options = options.merge(
    bucket: @bucket_name,
    key: @key
  )
  resp = Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    @client.restore_object(options)
  end
  resp.data
end

#restore_statusTypes::RestoreStatus



146
147
148
# File 'lib/aws-sdk-s3/object_summary.rb', line 146

def restore_status
  data[:restore_status]
end

#size::Integer Also known as: content_length

Returns:

  • (::Integer)


101
102
103
# File 'lib/aws-sdk-s3/object_summary.rb', line 101

def size
  data[:size]
end

#storage_class"STANDARD", ...

Returns:

  • ("STANDARD", "REDUCED_REDUNDANCY", "GLACIER", "STANDARD_IA", "ONEZONE_IA", "INTELLIGENT_TIERING", "DEEP_ARCHIVE", "OUTPOSTS", "GLACIER_IR", "SNOW", "EXPRESS_ONEZONE", "FSX_OPENZFS", "FSX_ONTAP")


114
115
116
# File 'lib/aws-sdk-s3/object_summary.rb', line 114

def storage_class
  data[:storage_class]
end

#upload_file(source, options = {}) ⇒ void

Parameters:

  • source (Object)
  • options (Hash[Symbol, untyped]) (defaults to: {})


64
65
66
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 64

def upload_file(source, options = {})
  object.upload_file(source, options)
end

#upload_stream(options = {}) {|write_stream| ... } ⇒ Boolean

Parameters:

  • options (Hash[Symbol, untyped]) (defaults to: {})

Yields:

Yield Parameters:

  • write_stream (IO)

Yield Returns:

  • (void)

Returns:

  • (Boolean)


71
72
73
# File 'lib/aws-sdk-s3/customizations/object_summary.rb', line 71

def upload_stream(options = {}, &block)
  object.upload_stream(options, &block)
end

#version(id) ⇒ ObjectVersion

Parameters:

  • id (String)

Returns:



2968
2969
2970
2971
2972
2973
2974
2975
# File 'lib/aws-sdk-s3/object_summary.rb', line 2968

def version(id)
  ObjectVersion.new(
    bucket_name: @bucket_name,
    object_key: @key,
    id: id,
    client: @client
  )
end

#wait_until(options = {}) {|resource| ... } ⇒ Resource

Deprecated.

Use [Aws::S3::Client] #wait_until instead

Note:

The waiting operation is performed on a copy. The original resource remains unchanged.

Waiter polls an API operation until a resource enters a desired state.

Basic Usage

Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.

# polls in a loop until condition is true
resource.wait_until(options) {|resource| condition}

Example

instance.wait_until(max_attempts:10, delay:5) do |instance|
  instance.state.name == 'running'
end

Configuration

You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:

# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}

Callbacks

You can be notified before each polling attempt and before each delay. If you throw :success or :failure from these callbacks, it will terminate the waiter.

started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
  throw :failure if Time.now - started_at > 3600
end

  # disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}

Handling Errors

When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.

begin
  resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
  # resource did not enter the desired state in time
end

attempts attempt in seconds invoked before each attempt invoked before each wait

Parameters:

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

    a customizable set of options

Options Hash (options):

  • :max_attempts (Integer) — default: 10

    Maximum number of

  • :delay (Integer) — default: 10

    Delay between each

  • :before_attempt (Proc) — default: nil

    Callback

  • :before_wait (Proc) — default: nil

    Callback

Yield Parameters:

  • resource (Resource)

    to be used in the waiting condition.

Returns:

  • (Resource)

    if the waiter was successful

Raises:

  • (Aws::Waiters::Errors::FailureStateError)

    Raised when the waiter terminates because the waiter has entered a state that it will not transition out of, preventing success.

    yet successful.

  • (Aws::Waiters::Errors::UnexpectedError)

    Raised when an error is encountered while polling for a resource that is not expected.

  • (NotImplementedError)

    Raised when the resource does not



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/aws-sdk-s3/object_summary.rb', line 316

def wait_until(options = {}, &block)
  self_copy = self.dup
  attempts = 0
  options[:max_attempts] = 10 unless options.key?(:max_attempts)
  options[:delay] ||= 10
  options[:poller] = Proc.new do
    attempts += 1
    if block.call(self_copy)
      [:success, self_copy]
    else
      self_copy.reload unless attempts == options[:max_attempts]
      :retry
    end
  end
  Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    Aws::Waiters::Waiter.new(options).wait({})
  end
end

#wait_until_exists(max_attempts:, delay:, before_attempt:, before_wait:) ⇒ void #wait_until_exists(arg0) ⇒ void

Overloads:

  • #wait_until_exists(max_attempts:, delay:, before_attempt:, before_wait:) ⇒ void

    This method returns an undefined value.

    Parameters:

    • max_attempts: (Integer)
    • delay: (Numeric)
    • before_attempt: (^(Integer attempts) -)

      void]

    • before_wait: (^(Integer attempts, untyped response) -)

      void]

  • #wait_until_exists(arg0) ⇒ void

    This method returns an undefined value.

    Parameters:

    • arg0 (Hash[Symbol, untyped])


200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/aws-sdk-s3/object_summary.rb', line 200

def wait_until_exists(options = {}, &block)
  options, params = separate_params_and_options(options)
  waiter = Waiters::ObjectExists.new(options)
  yield_waiter_and_warn(waiter, &block) if block_given?
  Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    waiter.wait(params.merge(bucket: @bucket_name,
    key: @key))
  end
  ObjectSummary.new({
    bucket_name: @bucket_name,
    key: @key,
    client: @client
  })
end

#wait_until_not_exists(max_attempts:, delay:, before_attempt:, before_wait:) ⇒ void #wait_until_not_exists(arg0) ⇒ void

Overloads:

  • #wait_until_not_exists(max_attempts:, delay:, before_attempt:, before_wait:) ⇒ void

    This method returns an undefined value.

    Parameters:

    • max_attempts: (Integer)
    • delay: (Numeric)
    • before_attempt: (^(Integer attempts) -)

      void]

    • before_wait: (^(Integer attempts, untyped response) -)

      void]

  • #wait_until_not_exists(arg0) ⇒ void

    This method returns an undefined value.

    Parameters:

    • arg0 (Hash[Symbol, untyped])


221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/aws-sdk-s3/object_summary.rb', line 221

def wait_until_not_exists(options = {}, &block)
  options, params = separate_params_and_options(options)
  waiter = Waiters::ObjectNotExists.new(options)
  yield_waiter_and_warn(waiter, &block) if block_given?
  Aws::Plugins::UserAgent.metric('RESOURCE_MODEL') do
    waiter.wait(params.merge(bucket: @bucket_name,
    key: @key))
  end
  ObjectSummary.new({
    bucket_name: @bucket_name,
    key: @key,
    client: @client
  })
end