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
-
#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
22 23 24 25 26 27 28 29 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 22 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.
63 64 65 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 63 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.
74 75 76 77 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 74 def move_to(target, = {}) copy_to(target, ) delete end |
#presigned_post(options = {}) ⇒ PresignedPost
The ‘:key` is populated by #key. Do not specify the `:key` or `:key_starts_with` options.
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.
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 89 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.
146 147 148 149 150 151 152 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 146 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"
169 170 171 172 173 174 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 169 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')
206 207 208 209 210 211 212 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 206 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 |