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.
- #extension ⇒ Object
- #filename ⇒ Object
-
#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
122 123 124 125 126 127 128 129 130 |
# File 'lib/carrierwave/storage/aliyun.rb', line 122 def delete begin oss_connection.delete(@path) true rescue Exception => e # If the file's not there, don't panic nil end end |
#extension ⇒ Object
98 99 100 |
# File 'lib/carrierwave/storage/aliyun.rb', line 98 def extension @path.split('.').last end |
#filename ⇒ Object
102 103 104 |
# File 'lib/carrierwave/storage/aliyun.rb', line 102 def filename @path.split('/').last 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
113 114 115 116 117 |
# File 'lib/carrierwave/storage/aliyun.rb', line 113 def read object = oss_connection.get(@path) @headers = object.headers object.body end |
#store(data, opts = {}) ⇒ Object
136 137 138 |
# File 'lib/carrierwave/storage/aliyun.rb', line 136 def store(data, opts = {}) oss_connection.put(@path, data, opts) end |
#url ⇒ Object
132 133 134 |
# File 'lib/carrierwave/storage/aliyun.rb', line 132 def url "http://oss.aliyuncs.com/#{@uploader.aliyun_bucket}/#{@path}" end |