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



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

#extensionObject



98
99
100
# File 'lib/carrierwave/storage/aliyun.rb', line 98

def extension
  @path.split('.').last
end

#filenameObject



102
103
104
# File 'lib/carrierwave/storage/aliyun.rb', line 102

def filename
  @path.split('/').last
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



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

#urlObject



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

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