Class: CarrierWave::Storage::Aliyun::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::Aliyun::File
- Defined in:
- lib/carrierwave/storage/aliyun.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
Returns the value of attribute content_type.
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(data, opts = {}) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(uploader, base, path) ⇒ File
Returns a new instance of File.
81 82 83 84 85 |
# File 'lib/carrierwave/storage/aliyun.rb', line 81 def initialize(uploader, base, path) @uploader = uploader @path = path @base = base end |
Instance Attribute Details
#content_type ⇒ Object
Returns the value of attribute content_type.
79 80 81 |
# File 'lib/carrierwave/storage/aliyun.rb', line 79 def content_type @content_type end |
Instance Method Details
#delete ⇒ Object
Remove the file from Cloud Files
114 115 116 117 118 119 120 121 122 |
# File 'lib/carrierwave/storage/aliyun.rb', line 114 def delete begin oss_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
94 95 96 |
# File 'lib/carrierwave/storage/aliyun.rb', line 94 def path @path end |
#read ⇒ Object
Reads the contents of the file from Cloud Files
Returns
- String
-
contents of the file
105 106 107 108 109 |
# File 'lib/carrierwave/storage/aliyun.rb', line 105 def read object = oss_connection.get(@path) @headers = object.headers object.body end |
#store(data, opts = {}) ⇒ Object
128 129 130 |
# File 'lib/carrierwave/storage/aliyun.rb', line 128 def store(data, opts = {}) oss_connection.put(@path, data, opts) end |
#url ⇒ Object
124 125 126 |
# File 'lib/carrierwave/storage/aliyun.rb', line 124 def url "http://oss.aliyuncs.com/#{@uploader.aliyun_bucket}/#{@path}" end |