Class: CarrierWave::Storage::Aliyun::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::Aliyun::File
- Defined in:
- lib/carrierwave/storage/aliyun.rb
Instance Method Summary collapse
-
#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(file, opts = {}) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(uploader, base, path) ⇒ File
Returns a new instance of File.
122 123 124 125 126 |
# File 'lib/carrierwave/storage/aliyun.rb', line 122 def initialize(uploader, base, path) @uploader = uploader @path = path @base = base end |
Instance Method Details
#delete ⇒ Object
Remove the file from Cloud Files
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/carrierwave/storage/aliyun.rb', line 154 def delete begin oss_connection.delete(@path) true rescue Exception => e # If the file's not there, don't panic puts "carrierwave-aliyun delete file failed: #{e}" nil end end |
#path ⇒ Object
Returns the current path/filename of the file on Cloud Files.
Returns
- String
-
A path
135 136 137 |
# File 'lib/carrierwave/storage/aliyun.rb', line 135 def path @path end |
#read ⇒ Object
Reads the contents of the file from Cloud Files
Returns
- String
-
contents of the file
146 147 148 149 |
# File 'lib/carrierwave/storage/aliyun.rb', line 146 def read object = oss_connection.get(@path) object.data end |
#store(file, opts = {}) ⇒ Object
169 170 171 |
# File 'lib/carrierwave/storage/aliyun.rb', line 169 def store(file, opts = {}) oss_connection.put(@path, file, opts) end |
#url ⇒ Object
165 166 167 |
# File 'lib/carrierwave/storage/aliyun.rb', line 165 def url oss_connection.path_to_url(@path, :get => true) end |