Class: CarrierWave::Storage::AWSFile
- Inherits:
-
Object
- Object
- CarrierWave::Storage::AWSFile
- Defined in:
- lib/carrierwave/storage/aws_file.rb
Instance Attribute Summary collapse
-
#aws_options ⇒ Object
Returns the value of attribute aws_options.
-
#connection ⇒ Object
Returns the value of attribute connection.
- #file ⇒ Object (also: #to_file)
-
#path ⇒ Object
Returns the value of attribute path.
-
#uploader ⇒ Object
Returns the value of attribute uploader.
Instance Method Summary collapse
- #attributes ⇒ Object
- #authenticated_url(options = {}) ⇒ Object
- #copy_to(new_path) ⇒ Object
- #extension ⇒ Object
- #filename(options = {}) ⇒ Object
-
#initialize(uploader, connection, path) ⇒ AWSFile
constructor
A new instance of AWSFile.
- #move_to(new_path) ⇒ Object
- #public_url ⇒ Object
- #read ⇒ Object
- #signed_url(options = {}) ⇒ Object
- #size ⇒ Object
- #store(new_file) ⇒ Object
- #url(options = {}) ⇒ Object
Constructor Details
#initialize(uploader, connection, path) ⇒ AWSFile
Returns a new instance of AWSFile.
11 12 13 14 15 16 |
# File 'lib/carrierwave/storage/aws_file.rb', line 11 def initialize(uploader, connection, path) @uploader = uploader @connection = connection @path = path @aws_options = AWSOptions.new(uploader) end |
Instance Attribute Details
#aws_options ⇒ Object
Returns the value of attribute aws_options.
7 8 9 |
# File 'lib/carrierwave/storage/aws_file.rb', line 7 def @aws_options end |
#connection ⇒ Object
Returns the value of attribute connection.
7 8 9 |
# File 'lib/carrierwave/storage/aws_file.rb', line 7 def connection @connection end |
#file ⇒ Object Also known as: to_file
18 19 20 |
# File 'lib/carrierwave/storage/aws_file.rb', line 18 def file @file ||= bucket.object(path) end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/carrierwave/storage/aws_file.rb', line 7 def path @path end |
#uploader ⇒ Object
Returns the value of attribute uploader.
7 8 9 |
# File 'lib/carrierwave/storage/aws_file.rb', line 7 def uploader @uploader end |
Instance Method Details
#attributes ⇒ Object
30 31 32 |
# File 'lib/carrierwave/storage/aws_file.rb', line 30 def attributes file.data.to_h end |
#authenticated_url(options = {}) ⇒ Object
81 82 83 |
# File 'lib/carrierwave/storage/aws_file.rb', line 81 def authenticated_url( = {}) file.presigned_url(:get, .()) end |
#copy_to(new_path) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/carrierwave/storage/aws_file.rb', line 63 def copy_to(new_path) bucket.object(new_path).copy_from( "#{bucket.name}/#{file.key}", .(self) ) end |
#extension ⇒ Object
34 35 36 37 |
# File 'lib/carrierwave/storage/aws_file.rb', line 34 def extension elements = path.split('.') elements.last if elements.size > 1 end |
#filename(options = {}) ⇒ Object
39 40 41 42 43 |
# File 'lib/carrierwave/storage/aws_file.rb', line 39 def filename( = {}) file_url = url() CarrierWave::Support::UriFilename.filename(file_url) if file_url end |
#move_to(new_path) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/carrierwave/storage/aws_file.rb', line 70 def move_to(new_path) file.move_to( "#{bucket.name}/#{new_path}", .(self) ) end |
#public_url ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/carrierwave/storage/aws_file.rb', line 85 def public_url if uploader.asset_host "#{uploader.asset_host}/#{uri_path}" else file.public_url.to_s end end |
#read ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/carrierwave/storage/aws_file.rb', line 45 def read = . if block_given? file.get() { |chunk| yield chunk } nil else file.get().body.read end end |
#signed_url(options = {}) ⇒ Object
77 78 79 |
# File 'lib/carrierwave/storage/aws_file.rb', line 77 def signed_url( = {}) signer.call(public_url.dup, ) end |
#size ⇒ Object
22 23 24 25 26 |
# File 'lib/carrierwave/storage/aws_file.rb', line 22 def size file.size rescue Aws::S3::Errors::NotFound nil end |
#store(new_file) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/carrierwave/storage/aws_file.rb', line 55 def store(new_file) if new_file.is_a?(self.class) new_file.move_to(path) else file.upload_file(new_file.path, .(new_file)) end end |
#url(options = {}) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/carrierwave/storage/aws_file.rb', line 93 def url( = {}) if signer signed_url() elsif public? public_url else authenticated_url() end end |