Class: CarrierWave::Storage::Aliyun::Connection
- Inherits:
-
Object
- Object
- CarrierWave::Storage::Aliyun::Connection
- Defined in:
- lib/carrierwave/storage/aliyun.rb
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #get(path, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #put(path, file, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/carrierwave/storage/aliyun.rb', line 14 def initialize(={}) @aliyun_access_id = [:aliyun_access_id] @aliyun_access_key = [:aliyun_access_key] @aliyun_bucket = [:aliyun_bucket] @aliyun_host = "oss.aliyuncs.com" if [:aliyun_internal] == true @aliyun_host = "oss-internal.aliyuncs.com" end @http = Net::HTTP.new(@aliyun_host) end |
Instance Method Details
#delete(path) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/carrierwave/storage/aliyun.rb', line 40 def delete path path = "#{@aliyun_bucket}/#{path}" url = "http://#{@aliyun_host}/#{path}" date = Time.now.gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT") headers = { "Authorization" => sign("DELETE", path, "", "", date), "Date" => date, "Host" => @aliyun_host, } RestClient.delete URI.escape(url), headers end |
#get(path, options = {}) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/carrierwave/storage/aliyun.rb', line 33 def get(path, ={}) path = "#{@aliyun_bucket}/#{path}" url = "http://#{@aliyun_host}/#{path}" headers = generate_header "GET", path, "", RestClient.get URI.escape(url), headers end |
#put(path, file, options = {}) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/carrierwave/storage/aliyun.rb', line 25 def put(path, file, ={}) content_md5 = Digest::MD5.hexdigest(file) path = "#{@aliyun_bucket}/#{path}" url = "http://#{@aliyun_host}/#{path}" headers = generate_header("PUT", path, content_md5, ).merge!({"Content-Length" => file.length}) RestClient.put URI.escape(url), file, headers end |