Class: CarrierWave::Storage::AWSFile
- Inherits:
-
Object
- Object
- CarrierWave::Storage::AWSFile
- Defined in:
- lib/carrierwave/storage/aws_file.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(options = {}) ⇒ Object
- #copy_to(new_path) ⇒ Object
- #delete ⇒ Object
- #exists? ⇒ Boolean
- #extension ⇒ Object
- #filename(options = {}) ⇒ Object
-
#initialize(uploader, connection, path) ⇒ AWSFile
constructor
A new instance of AWSFile.
- #public_url ⇒ Object
- #read ⇒ Object
- #size ⇒ Object
- #store(new_file) ⇒ Object
- #to_file ⇒ Object
- #uploader_copy_options ⇒ Object
- #uploader_read_options ⇒ Object
- #uploader_write_options(new_file) ⇒ Object
- #url(options = {}) ⇒ Object
Constructor Details
#initialize(uploader, connection, path) ⇒ AWSFile
Returns a new instance of AWSFile.
7 8 9 10 11 |
# File 'lib/carrierwave/storage/aws_file.rb', line 7 def initialize(uploader, connection, path) @uploader = uploader @connection = connection @path = path end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/carrierwave/storage/aws_file.rb', line 5 def connection @connection end |
#content_type ⇒ Object
17 18 19 |
# File 'lib/carrierwave/storage/aws_file.rb', line 17 def content_type @content_type || file.content_type end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/carrierwave/storage/aws_file.rb', line 5 def path @path end |
#uploader ⇒ Object (readonly)
Returns the value of attribute uploader.
5 6 7 |
# File 'lib/carrierwave/storage/aws_file.rb', line 5 def uploader @uploader end |
Instance Method Details
#attributes ⇒ Object
13 14 15 |
# File 'lib/carrierwave/storage/aws_file.rb', line 13 def attributes file.head.data end |
#authenticated_url(options = {}) ⇒ Object
65 66 67 |
# File 'lib/carrierwave/storage/aws_file.rb', line 65 def authenticated_url( = {}) file.url_for(:read, { expires: uploader.aws_authenticated_url_expiration }.merge()).to_s end |
#copy_to(new_path) ⇒ Object
77 78 79 |
# File 'lib/carrierwave/storage/aws_file.rb', line 77 def copy_to(new_path) file.copy_to(bucket.objects[new_path], ) end |
#delete ⇒ Object
21 22 23 |
# File 'lib/carrierwave/storage/aws_file.rb', line 21 def delete file.delete end |
#exists? ⇒ Boolean
29 30 31 |
# File 'lib/carrierwave/storage/aws_file.rb', line 29 def exists? file.exists? end |
#extension ⇒ Object
25 26 27 |
# File 'lib/carrierwave/storage/aws_file.rb', line 25 def extension path.split('.').last end |
#filename(options = {}) ⇒ Object
33 34 35 36 37 |
# File 'lib/carrierwave/storage/aws_file.rb', line 33 def filename( = {}) if file_url = url() URI.decode(file_url.split('?').first).gsub(/.*\/(.*?$)/, '\1') end end |
#public_url ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/carrierwave/storage/aws_file.rb', line 69 def public_url if uploader.asset_host "#{uploader.asset_host}/#{path}" else file.public_url.to_s end end |
#read ⇒ Object
39 40 41 |
# File 'lib/carrierwave/storage/aws_file.rb', line 39 def read file.read() end |
#size ⇒ Object
43 44 45 |
# File 'lib/carrierwave/storage/aws_file.rb', line 43 def size file.content_length end |
#store(new_file) ⇒ Object
47 48 49 50 51 |
# File 'lib/carrierwave/storage/aws_file.rb', line 47 def store(new_file) @file = bucket.objects[path].write((new_file)) true end |
#to_file ⇒ Object
53 54 55 |
# File 'lib/carrierwave/storage/aws_file.rb', line 53 def to_file file end |
#uploader_copy_options ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/carrierwave/storage/aws_file.rb', line 95 def = uploader. || {} = .select do |key,_| [:reduced_redundancy, :storage_class, :server_side_encryption].include?(key) end { acl: uploader.aws_acl }.merge() end |
#uploader_read_options ⇒ Object
81 82 83 |
# File 'lib/carrierwave/storage/aws_file.rb', line 81 def uploader. || {} end |
#uploader_write_options(new_file) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/carrierwave/storage/aws_file.rb', line 85 def (new_file) aws_attributes = uploader.aws_attributes || {} = uploader. || {} { acl: uploader.aws_acl, content_type: new_file.content_type, file: new_file.path }.merge(aws_attributes).merge() end |
#url(options = {}) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/carrierwave/storage/aws_file.rb', line 57 def url( = {}) if uploader.aws_acl != :public_read authenticated_url() else public_url end end |