Class: CarrierWave::Storage::AWS::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::AWS::File
- Defined in:
- lib/carrierwave/storage/aws.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
- #content_type ⇒ Object
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#uploader ⇒ Object
readonly
Returns the value of attribute uploader.
Instance Method Summary collapse
- #attributes ⇒ Object
- #authenticated_url ⇒ Object
- #delete ⇒ Object
- #exists? ⇒ Boolean
- #extension ⇒ Object
- #filename(options = {}) ⇒ Object
-
#initialize(uploader, connection, path) ⇒ File
constructor
A new instance of File.
- #public_url ⇒ Object
- #read ⇒ Object
- #size ⇒ Object
- #store(new_file) ⇒ Object
- #to_file ⇒ Object
- #url(options = {}) ⇒ Object
Constructor Details
#initialize(uploader, connection, path) ⇒ File
Returns a new instance of File.
35 36 37 38 39 |
# File 'lib/carrierwave/storage/aws.rb', line 35 def initialize(uploader, connection, path) @uploader = uploader @connection = connection @path = path end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
33 34 35 |
# File 'lib/carrierwave/storage/aws.rb', line 33 def connection @connection end |
#content_type ⇒ Object
45 46 47 |
# File 'lib/carrierwave/storage/aws.rb', line 45 def content_type @content_type || file.content_type end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
33 34 35 |
# File 'lib/carrierwave/storage/aws.rb', line 33 def path @path end |
#uploader ⇒ Object (readonly)
Returns the value of attribute uploader.
33 34 35 |
# File 'lib/carrierwave/storage/aws.rb', line 33 def uploader @uploader end |
Instance Method Details
#attributes ⇒ Object
41 42 43 |
# File 'lib/carrierwave/storage/aws.rb', line 41 def attributes file.attributes end |
#authenticated_url ⇒ Object
97 98 99 |
# File 'lib/carrierwave/storage/aws.rb', line 97 def authenticated_url file.url_for(:read, expires: uploader.aws_authenticated_url_expiration).to_s end |
#delete ⇒ Object
49 50 51 |
# File 'lib/carrierwave/storage/aws.rb', line 49 def delete file.delete end |
#exists? ⇒ Boolean
57 58 59 |
# File 'lib/carrierwave/storage/aws.rb', line 57 def exists? !!file end |
#extension ⇒ Object
53 54 55 |
# File 'lib/carrierwave/storage/aws.rb', line 53 def extension path.split('.').last end |
#filename(options = {}) ⇒ Object
61 62 63 64 65 |
# File 'lib/carrierwave/storage/aws.rb', line 61 def filename( = {}) if file_url = url() file_url.gsub(/.*\/(.*?$)/, '\1') end end |
#public_url ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/carrierwave/storage/aws.rb', line 101 def public_url if uploader.asset_host "#{uploader.asset_host}/#{path}" else file.public_url.to_s end end |
#read ⇒ Object
67 68 69 |
# File 'lib/carrierwave/storage/aws.rb', line 67 def read file.read end |
#size ⇒ Object
71 72 73 |
# File 'lib/carrierwave/storage/aws.rb', line 71 def size file.content_length end |
#store(new_file) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/carrierwave/storage/aws.rb', line 75 def store(new_file) @file = bucket.objects[path].write({ acl: uploader.aws_acl, content_type: new_file.content_type, file: new_file.path }.merge(uploader.aws_attributes || {})) true end |
#to_file ⇒ Object
85 86 87 |
# File 'lib/carrierwave/storage/aws.rb', line 85 def to_file file end |
#url(options = {}) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/carrierwave/storage/aws.rb', line 89 def url( = {}) if uploader.aws_acl != :public_read authenticated_url else public_url end end |