Class: CarrierWave::Storage::Aliyun::File
- Inherits:
-
CarrierWave::SanitizedFile
- Object
- CarrierWave::SanitizedFile
- CarrierWave::Storage::Aliyun::File
- Defined in:
- lib/carrierwave/storage/aliyun.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the current path/filename of the file on Cloud Files.
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.
-
#read ⇒ Object
Reads the contents of the file from Cloud Files.
- #store(file, opts = {}) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(uploader, base, path) ⇒ File
Returns a new instance of File.
146 147 148 149 150 |
# File 'lib/carrierwave/storage/aliyun.rb', line 146 def initialize(uploader, base, path) @uploader = uploader @path = URI.encode(path) @base = base end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the current path/filename of the file on Cloud Files.
Returns
- String
-
A path
144 145 146 |
# File 'lib/carrierwave/storage/aliyun.rb', line 144 def path @path end |
Instance Method Details
#content_type ⇒ Object
186 187 188 |
# File 'lib/carrierwave/storage/aliyun.rb', line 186 def content_type headers[:content_type] end |
#content_type=(new_content_type) ⇒ Object
190 191 192 |
# File 'lib/carrierwave/storage/aliyun.rb', line 190 def content_type=(new_content_type) headers[:content_type] = new_content_type end |
#delete ⇒ Object
Remove the file from Cloud Files
169 170 171 172 173 174 175 176 |
# File 'lib/carrierwave/storage/aliyun.rb', line 169 def delete oss_connection.delete(@path) true rescue => e # If the file's not there, don't panic puts "carrierwave-aliyun delete file failed: #{e}" nil end |
#read ⇒ Object
Reads the contents of the file from Cloud Files
Returns
- String
-
contents of the file
159 160 161 162 163 164 |
# File 'lib/carrierwave/storage/aliyun.rb', line 159 def read body = "" object = oss_connection.get(@path){|chunk| body << chunk} @headers = object.headers body end |
#store(file, opts = {}) ⇒ Object
194 195 196 |
# File 'lib/carrierwave/storage/aliyun.rb', line 194 def store(file, opts = {}) oss_connection.put(@path, file, opts) end |
#url ⇒ Object
178 179 180 181 182 183 184 |
# File 'lib/carrierwave/storage/aliyun.rb', line 178 def url if @uploader.aliyun_private_read oss_connection.private_get_url(@path) else oss_connection.path_to_url(@path) end end |