Class: Notebook::StorageAdapters::S3
- Defined in:
- lib/notebook/storage_adapters/s3.rb
Instance Attribute Summary collapse
-
#s3_file_key ⇒ Object
readonly
Returns the value of attribute s3_file_key.
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(attachment, options = {}) ⇒ S3
constructor
A new instance of S3.
- #upload ⇒ Object
- #url ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(attachment, options = {}) ⇒ S3
Returns a new instance of S3.
19 20 21 22 23 24 |
# File 'lib/notebook/storage_adapters/s3.rb', line 19 def initialize(, = {}) super #-- check_valid_credentials setup_s3 end |
Instance Attribute Details
#s3_file_key ⇒ Object (readonly)
Returns the value of attribute s3_file_key.
17 18 19 |
# File 'lib/notebook/storage_adapters/s3.rb', line 17 def s3_file_key @s3_file_key end |
Instance Method Details
#delete ⇒ Object
26 27 28 |
# File 'lib/notebook/storage_adapters/s3.rb', line 26 def delete @bucket.object(@s3_file_key).delete end |
#upload ⇒ Object
30 31 32 33 34 |
# File 'lib/notebook/storage_adapters/s3.rb', line 30 def upload @s3_file_key = "#{SecureRandom.uuid}/#{File.basename(attachment.file)}" @file_object = @bucket.object(@s3_file_key) @file_object.upload_file(.file.path) end |
#url ⇒ Object
36 37 38 |
# File 'lib/notebook/storage_adapters/s3.rb', line 36 def url @bucket.object(@s3_file_key).presigned_url(:get) end |