Class: Aws::S3::Object
- Inherits:
-
Object
- Object
- Aws::S3::Object
- Defined in:
- lib/aws-sdk-resources/services/s3/object.rb
Instance Method Summary collapse
-
#presigned_url(http_method, params = {}) ⇒ String
Generates a pre-signed URL for this object.
-
#public_url ⇒ 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
#presigned_url(http_method, params = {}) ⇒ String
Generates a pre-signed URL for this object.
45 46 47 48 49 50 51 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 45 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 ⇒ 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"
59 60 61 62 63 64 65 66 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 59 def public_url PublicUrl.build( endpoint: client.config.endpoint, bucket_name: bucket_name, object_key: key, force_path_style: client.config.force_path_style ) 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')
98 99 100 101 102 103 104 |
# File 'lib/aws-sdk-resources/services/s3/object.rb', line 98 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 |