Class: S3FileHandler::File::Upload
- Inherits:
-
BaseOperation
- Object
- BaseOperation
- S3FileHandler::File::Upload
- Defined in:
- lib/s3_file_handler/file/upload.rb
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
readonly
Returns the value of attribute bucket_name.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#file_key ⇒ Object
readonly
Returns the value of attribute file_key.
-
#local_path ⇒ Object
readonly
Returns the value of attribute local_path.
Attributes inherited from BaseOperation
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(bucket_name, file_key, content: nil, local_path: nil, client: S3FileHandler.client) ⇒ Upload
constructor
A new instance of Upload.
Constructor Details
#initialize(bucket_name, file_key, content: nil, local_path: nil, client: S3FileHandler.client) ⇒ Upload
Returns a new instance of Upload.
8 9 10 11 12 13 14 15 |
# File 'lib/s3_file_handler/file/upload.rb', line 8 def initialize(bucket_name, file_key, content: nil, local_path: nil, client: S3FileHandler.client) super(client: client) @bucket_name = bucket_name @file_key = file_key @content = content @local_path = local_path end |
Instance Attribute Details
#bucket_name ⇒ Object (readonly)
Returns the value of attribute bucket_name.
6 7 8 |
# File 'lib/s3_file_handler/file/upload.rb', line 6 def bucket_name @bucket_name end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
6 7 8 |
# File 'lib/s3_file_handler/file/upload.rb', line 6 def content @content end |
#file_key ⇒ Object (readonly)
Returns the value of attribute file_key.
6 7 8 |
# File 'lib/s3_file_handler/file/upload.rb', line 6 def file_key @file_key end |
#local_path ⇒ Object (readonly)
Returns the value of attribute local_path.
6 7 8 |
# File 'lib/s3_file_handler/file/upload.rb', line 6 def local_path @local_path end |
Instance Method Details
#execute ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/s3_file_handler/file/upload.rb', line 17 def execute handle_aws_errors do body = content || ::File.open(local_path, 'rb') client.put_object( bucket: bucket_name, key: file_key, body: body ) result({ bucket: bucket_name, key: file_key, status: 'uploaded' }) end end |