Class: Aws::S3::Object
- Inherits:
-
Object
- Object
- Aws::S3::Object
- Defined in:
- lib/aws-sdk-resources/services/s3/object.rb
Instance Method Summary collapse
-
#copy_from(source, options = {}) ⇒ Object
Copies another object to this object.
-
#copy_to(target, options = {}) ⇒ Object
Copies this object to another object.
-
#move_to(target, options = {}) ⇒ void
Copies and deletes the current object.
-
#presigned_post(options = {}) ⇒ PresignedPost
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.
-
#presigned_url(http_method, params = {}) ⇒ String
Generates a pre-signed URL for this object.
-
#public_url(options = {}) ⇒ String
Returns the public (un-signed) URL for this object.
-
#upload_file(source, options = {}) ⇒ Boolean
Uploads a file from disk to the current object in S3.
Instance Method Details
#copy_from(source, options = {}) ⇒ Object
Copies another object to this object. Use ‘multipart_copy: true` for large objects. This is required for objects that exceed 5GB.’
44 45 46 47 48 49 50 51 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 44 def copy_from(source, = {}) if Hash === source && source[:copy_source] # for backwards compatibility @client.copy_object(source.merge(bucket: bucket_name, key: key)) else ObjectCopier.new(self, ).copy_from(source, ) end end |
#copy_to(target, options = {}) ⇒ Object
If you need to copy to a bucket in a different region, use #copy_from.
Copies this object to another object. Use ‘multipart_copy: true` for large objects. This is required for objects that exceed 5GB.
85 86 87 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 85 def copy_to(target, = {}) ObjectCopier.new(self, ).copy_to(target, ) end |
#move_to(target, options = {}) ⇒ void
This method returns an undefined value.
Copies and deletes the current object. The object will only be deleted if the copy operation succeeds.
96 97 98 99 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 96 def move_to(target, = {}) copy_to(target, ) delete end |
#presigned_post(options = {}) ⇒ PresignedPost
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.
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 110 def presigned_post( = {}) PresignedPost.new( client.config.credentials, client.config.region, bucket_name, { key: key, url: bucket.url, }.merge() ) end |
#presigned_url(http_method, params = {}) ⇒ String
Generates a pre-signed URL for this object.
167 168 169 170 171 172 173 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 167 def presigned_url(http_method, params = {}) presigner = Presigner.new(client: client) presigner.presigned_url("#{http_method.downcase}_object", params.merge( bucket: bucket_name, key: key, )) end |
#public_url(options = {}) ⇒ String
Returns the public (un-signed) URL for this object.
s3.bucket('bucket-name').object('obj-key').public_url
#=> "https://bucket-name.s3.amazonaws.com/obj-key"
To use virtual hosted bucket url (disables https):
s3.bucket('my.bucket.com').object('key').public_url(virtual_host: true)
#=> "http://my.bucket.com/key"
190 191 192 193 194 195 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 190 def public_url( = {}) url = URI.parse(bucket.url()) url.path += '/' unless url.path[-1] == '/' url.path += key.gsub(/[^\/]+/) { |s| Seahorse::Util.uri_escape(s) } url.to_s end |
#upload_file(source, options = {}) ⇒ Boolean
Uploads a file from disk to the current object in S3.
# small files are uploaded in a single API call
obj.upload_file('/path/to/file')
Files larger than ‘:multipart_threshold` are uploaded using the Amazon S3 multipart upload APIs.
# large files are automatically split into parts
# and the parts are uploaded in parallel
obj.upload_file('/path/to/very_large_file')
227 228 229 230 231 232 233 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 227 def upload_file(source, = {}) uploader = FileUploader.new( multipart_threshold: .delete(:multipart_threshold), client: client) uploader.upload(source, .merge(bucket: bucket_name, key: key)) true end |