Class: Aws::S3::ObjectSummary
- Inherits:
-
Object
- Object
- Aws::S3::ObjectSummary
- Defined in:
- gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb,
gems/aws-sdk-s3/lib/aws-sdk-s3/customizations/object_summary.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#bucket_name ⇒ String
-
#etag ⇒ String
The entity tag is a hash of the object.
-
#key ⇒ String
-
#last_modified ⇒ Time
The date the Object was Last Modified.
-
#owner ⇒ Types::Owner
The owner of the object.
-
#size ⇒ Integer
(also: #content_length)
Size in bytes of the object.
-
#storage_class ⇒ String
The class of storage used to store the object.
Actions collapse
-
#copy_from(source, options = {}) ⇒ Object
-
#delete(options = {}) ⇒ Types::DeleteObjectOutput
-
#get(options = {}, &block) ⇒ Types::GetObjectOutput
-
#initiate_multipart_upload(options = {}) ⇒ MultipartUpload
-
#put(options = {}) ⇒ Types::PutObjectOutput
-
#restore_object(options = {}) ⇒ Types::RestoreObjectOutput
Associations collapse
-
#acl ⇒ ObjectAcl
-
#bucket ⇒ Bucket
-
#multipart_upload(id) ⇒ MultipartUpload
-
#object ⇒ Object
-
#version(id) ⇒ ObjectVersion
Instance Method Summary collapse
-
#client ⇒ Client
-
#copy_to(target, options = {}) ⇒ Object
-
#data ⇒ Types::Object
Returns the data for this ObjectSummary.
-
#data_loaded? ⇒ Boolean
Returns
true
if this resource is loaded. -
#download_file(destination, options = {}) ⇒ Boolean
Returns
true
when the file is downloaded without any errors. -
#exists?(options = {}) ⇒ Boolean
Returns
true
if the ObjectSummary exists. -
#initialize(*args) ⇒ ObjectSummary
constructor
A new instance of ObjectSummary.
-
#move_to(target, options = {}) ⇒ void
-
#presigned_post(options = {}) ⇒ PresignedPost
-
#presigned_url(http_method, params = {}) ⇒ String
-
#public_url(options = {}) ⇒ String
-
#upload_file(source, options = {}) ⇒ Boolean
Returns
true
when the object is uploaded without any errors. -
#upload_stream(options = {}, &block) ⇒ Boolean
Returns
true
when the object is uploaded without any errors. -
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::S3::Client] #wait_until instead
-
#wait_until_exists(options = {}, &block) ⇒ ObjectSummary
-
#wait_until_not_exists(options = {}, &block) ⇒ ObjectSummary
Constructor Details
#initialize(bucket_name, key, options = {}) ⇒ ObjectSummary #initialize(options = {}) ⇒ ObjectSummary
Returns a new instance of ObjectSummary.
24 25 26 27 28 29 30 31 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 24 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @bucket_name = extract_bucket_name(args, ) @key = extract_key(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() @waiter_block_warned = false end |
Instance Method Details
#acl ⇒ ObjectAcl
1197 1198 1199 1200 1201 1202 1203 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 1197 def acl ObjectAcl.new( bucket_name: @bucket_name, object_key: @key, client: @client ) end |
#bucket ⇒ Bucket
1206 1207 1208 1209 1210 1211 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 1206 def bucket Bucket.new( name: @bucket_name, client: @client ) end |
#bucket_name ⇒ String
36 37 38 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 36 def bucket_name @bucket_name end |
#client ⇒ Client
95 96 97 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 95 def client @client end |
#copy_from(source, options = {}) ⇒ Object
511 512 513 514 515 516 517 518 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 511 def copy_from( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.copy_object() resp.data end |
#copy_to(target, options = {}) ⇒ Object
24 25 26 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/customizations/object_summary.rb', line 24 def copy_to(target, = {}) object.copy_to(target, ) end |
#data ⇒ Types::Object
Returns the data for this Aws::S3::ObjectSummary.
110 111 112 113 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 110 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
Returns true
if this resource is loaded. Accessing attributes or
#data on an unloaded resource will trigger a call to #load.
118 119 120 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 118 def data_loaded? !!@data end |
#delete(options = {}) ⇒ Types::DeleteObjectOutput
555 556 557 558 559 560 561 562 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 555 def delete( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.delete_object() resp.data end |
#download_file(destination, options = {}) ⇒ Boolean
Returns true
when the file is downloaded without
any errors.
79 80 81 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/customizations/object_summary.rb', line 79 def download_file(destination, = {}) object.download_file(destination, ) end |
#etag ⇒ String
The entity tag is a hash of the object. The ETag reflects changes only to the contents of an object, not its metadata. The ETag may or may not be an MD5 digest of the object data. Whether or not it is depends on how the object was created and how it is encrypted as described below:
Objects created by the PUT Object, POST Object, or Copy operation, or through the AWS Management Console, and are encrypted by SSE-S3 or plaintext, have ETags that are an MD5 digest of their object data.
Objects created by the PUT Object, POST Object, or Copy operation, or through the AWS Management Console, and are encrypted by SSE-C or SSE-KMS, have ETags that are not an MD5 digest of their object data.
If an object is created by either the Multipart Upload or Part Copy operation, the ETag is not an MD5 digest, regardless of the method of encryption.
70 71 72 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 70 def etag data[:etag] end |
#exists?(options = {}) ⇒ Boolean
Returns true
if the ObjectSummary exists.
125 126 127 128 129 130 131 132 133 134 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 125 def exists?( = {}) begin wait_until_exists(.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) ⇒ Types::GetObjectOutput
659 660 661 662 663 664 665 666 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 659 def get( = {}, &block) = .merge( bucket: @bucket_name, key: @key ) resp = @client.get_object(, &block) resp.data end |
#initiate_multipart_upload(options = {}) ⇒ MultipartUpload
819 820 821 822 823 824 825 826 827 828 829 830 831 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 819 def initiate_multipart_upload( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.create_multipart_upload() MultipartUpload.new( bucket_name: @bucket_name, object_key: @key, id: resp.data.upload_id, client: @client ) end |
#key ⇒ String
41 42 43 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 41 def key @key end |
#last_modified ⇒ Time
The date the Object was Last Modified
47 48 49 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 47 def last_modified data[:last_modified] end |
#move_to(target, options = {}) ⇒ void
This method returns an undefined value.
32 33 34 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/customizations/object_summary.rb', line 32 def move_to(target, = {}) object.move_to(target, ) end |
#multipart_upload(id) ⇒ MultipartUpload
1215 1216 1217 1218 1219 1220 1221 1222 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 1215 def multipart_upload(id) MultipartUpload.new( bucket_name: @bucket_name, object_key: @key, id: id, client: @client ) end |
#object ⇒ Object
1225 1226 1227 1228 1229 1230 1231 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 1225 def object Object.new( bucket_name: @bucket_name, key: @key, client: @client ) end |
#owner ⇒ Types::Owner
The owner of the object
88 89 90 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 88 def owner data[:owner] end |
#presigned_post(options = {}) ⇒ PresignedPost
40 41 42 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/customizations/object_summary.rb', line 40 def presigned_post( = {}) object.presigned_post() end |
#presigned_url(http_method, params = {}) ⇒ String
48 49 50 |
# File 'gems/aws-sdk-s3/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
56 57 58 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/customizations/object_summary.rb', line 56 def public_url( = {}) object.public_url() end |
#put(options = {}) ⇒ Types::PutObjectOutput
1068 1069 1070 1071 1072 1073 1074 1075 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 1068 def put( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.put_object() resp.data end |
#restore_object(options = {}) ⇒ Types::RestoreObjectOutput
1185 1186 1187 1188 1189 1190 1191 1192 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 1185 def restore_object( = {}) = .merge( bucket: @bucket_name, key: @key ) resp = @client.restore_object() resp.data end |
#size ⇒ Integer Also known as: content_length
Size in bytes of the object
76 77 78 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 76 def size data[:size] end |
#storage_class ⇒ String
The class of storage used to store the object.
82 83 84 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 82 def storage_class data[:storage_class] end |
#upload_file(source, options = {}) ⇒ Boolean
Returns true
when the object is uploaded
without any errors.
64 65 66 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/customizations/object_summary.rb', line 64 def upload_file(source, = {}) object.upload_file(source, ) end |
#upload_stream(options = {}, &block) ⇒ Boolean
Returns true
when the object is uploaded
without any errors.
71 72 73 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/customizations/object_summary.rb', line 71 def upload_stream( = {}, &block) object.upload_stream(, &block) end |
#version(id) ⇒ ObjectVersion
1235 1236 1237 1238 1239 1240 1241 1242 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 1235 def version(id) ObjectVersion.new( bucket_name: @bucket_name, object_key: @key, id: id, client: @client ) end |
#wait_until(options = {}) {|resource| ... } ⇒ Resource
Use [Aws::S3::Client] #wait_until instead
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() {|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
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 254 def wait_until( = {}, &block) self_copy = self.dup attempts = 0 [:max_attempts] = 10 unless .key?(:max_attempts) [:delay] ||= 10 [:poller] = Proc.new do attempts += 1 if block.call(self_copy) [:success, self_copy] else self_copy.reload unless attempts == [:max_attempts] :retry end end Aws::Waiters::Waiter.new().wait({}) end |
#wait_until_exists(options = {}, &block) ⇒ ObjectSummary
142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 142 def wait_until_exists( = {}, &block) , params = () waiter = Waiters::ObjectExists.new() yield_waiter_and_warn(waiter, &block) if block_given? waiter.wait(params.merge(bucket: @bucket_name, key: @key)) ObjectSummary.new({ bucket_name: @bucket_name, key: @key, client: @client }) end |
#wait_until_not_exists(options = {}, &block) ⇒ ObjectSummary
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'gems/aws-sdk-s3/lib/aws-sdk-s3/object_summary.rb', line 161 def wait_until_not_exists( = {}, &block) , params = () waiter = Waiters::ObjectNotExists.new() yield_waiter_and_warn(waiter, &block) if block_given? waiter.wait(params.merge(bucket: @bucket_name, key: @key)) ObjectSummary.new({ bucket_name: @bucket_name, key: @key, client: @client }) end |