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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_typeObject

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

#deleteObject

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

#pathObject

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

#readObject

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

#urlObject



124
125
126
# File 'lib/carrierwave/storage/aliyun.rb', line 124

def url
  "http://oss.aliyuncs.com/#{@uploader.aliyun_bucket}/#{@path}"
end