Class: CarrierWave::Storage::UpYun::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::UpYun::File
- Defined in:
- lib/carrierwave/storage/upyun.rb
Instance Method Summary collapse
- #content_type ⇒ Object
- #content_type=(new_content_type) ⇒ Object
-
#delete ⇒ Object
Remove the file from Cloud Files.
-
#initialize(uploader, base, path) ⇒ File
constructor
A new instance of File.
-
#path ⇒ Object
Returns the current path/filename of the file on Cloud Files.
-
#read ⇒ Object
Reads the contents of the file from Cloud Files.
-
#store(data, headers = {}) ⇒ Object
Writes the supplied data into the object on Cloud Files.
-
#url ⇒ Object
Returns the url on the Cloud Files CDN.
Constructor Details
#initialize(uploader, base, path) ⇒ File
Returns a new instance of File.
71 72 73 74 75 |
# File 'lib/carrierwave/storage/upyun.rb', line 71 def initialize(uploader, base, path) @uploader = uploader @path = path @base = base end |
Instance Method Details
#content_type ⇒ Object
88 89 90 |
# File 'lib/carrierwave/storage/upyun.rb', line 88 def content_type @content_type || "" end |
#content_type=(new_content_type) ⇒ Object
92 93 94 |
# File 'lib/carrierwave/storage/upyun.rb', line 92 def content_type=(new_content_type) @content_type = new_content_type end |
#delete ⇒ Object
Remove the file from Cloud Files
112 113 114 115 116 117 118 119 120 |
# File 'lib/carrierwave/storage/upyun.rb', line 112 def delete begin upyun_connection.delete(@path) true rescue Exception => e # If the file's not there, don't panic nil end end |
#path ⇒ Object
Returns the current path/filename of the file on Cloud Files.
Returns
- String
-
A path
84 85 86 |
# File 'lib/carrierwave/storage/upyun.rb', line 84 def path @path end |
#read ⇒ Object
Reads the contents of the file from Cloud Files
Returns
- String
-
contents of the file
103 104 105 106 107 |
# File 'lib/carrierwave/storage/upyun.rb', line 103 def read object = upyun_connection.get(@path) @headers = object.headers object.net_http_res.body end |
#store(data, headers = {}) ⇒ Object
Writes the supplied data into the object on Cloud Files.
Returns
boolean
158 159 160 161 |
# File 'lib/carrierwave/storage/upyun.rb', line 158 def store(data,headers={}) upyun_connection.put(@path, data, {'Expect' => '', 'Mkdir' => 'true'}.merge(headers)) true end |
#url ⇒ Object
Returns the url on the Cloud Files CDN. Note that the parent container must be marked as public for this to work.
Returns
- String
-
file’s url
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/carrierwave/storage/upyun.rb', line 130 def url if @uploader.upyun_bucket_host return [@uploader.upyun_bucket_host, @path].join("/") end return nil unless @uploader.upyun_bucket_domain puts "DEPRECATION: upyun_bucket_domain config is deprecated, please use upyun_bucket_host to insead." bucket_host = @uploader.upyun_bucket_domain bucket_host.prepend('http://') unless bucket_host.match(/^http/) [bucket_host, @path].join("/") end |