Class: CarrierWave::Storage::Aliyun::File

Inherits:
CarrierWave::SanitizedFile
  • Object
show all
Defined in:
lib/carrierwave/storage/aliyun.rb

Instance Method Summary collapse

Constructor Details

#initialize(uploader, base, path) ⇒ File

Returns a new instance of File.



120
121
122
123
124
# File 'lib/carrierwave/storage/aliyun.rb', line 120

def initialize(uploader, base, path)
  @uploader = uploader
  @path     = URI.encode(path)
  @base     = base
end

Instance Method Details

#content_typeObject



172
173
174
# File 'lib/carrierwave/storage/aliyun.rb', line 172

def content_type
  headers[:content_type]
end

#content_type=(new_content_type) ⇒ Object



176
177
178
# File 'lib/carrierwave/storage/aliyun.rb', line 176

def content_type=(new_content_type)
  headers[:content_type] = new_content_type
end

#deleteObject

Remove the file from Cloud Files



153
154
155
156
157
158
159
160
161
162
# File 'lib/carrierwave/storage/aliyun.rb', line 153

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

#pathObject

Returns the current path/filename of the file on Cloud Files.

Returns

String

A path



133
134
135
# File 'lib/carrierwave/storage/aliyun.rb', line 133

def path
  @path
end

#readObject

Reads the contents of the file from Cloud Files

Returns

String

contents of the file



144
145
146
147
148
# File 'lib/carrierwave/storage/aliyun.rb', line 144

def read
  object = oss_connection.get(@path)
  @headers = object.headers
  object.body
end

#store(file, opts = {}) ⇒ Object



180
181
182
# File 'lib/carrierwave/storage/aliyun.rb', line 180

def store(file, opts = {})
  oss_connection.put(@path, file, opts)
end

#urlObject



164
165
166
167
168
169
170
# File 'lib/carrierwave/storage/aliyun.rb', line 164

def url
  if @uploader.aliyun_private_read
    oss_connection.private_get_url(@path)
  else
    oss_connection.path_to_url(@path)
  end
end