lib/carrierwave/storage/aliyun.rb in carrierwave-aliyun-0.1.0 vs lib/carrierwave/storage/aliyun.rb in carrierwave-aliyun-0.1.1
- old
+ new
@@ -11,25 +11,29 @@
class Connection
def initialize(options={})
@aliyun_access_id = options[:aliyun_access_id]
@aliyun_access_key = options[:aliyun_access_key]
@aliyun_bucket = options[:aliyun_bucket]
+ @aliyun_host = "oss.aliyuncs.com"
+ if options[:aliyun_internal] == true
+ @aliyun_host = "oss-internal.aliyuncs.com"
+ end
end
def put(path, file)
content_md5 = Digest::MD5.hexdigest(file)
content_type = "image/jpg"
date = Time.now.gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT")
path = "#{@aliyun_bucket}/#{path}"
- url = "http://storage.aliyun.com/#{path}"
+ url = "http://#{@aliyun_host}/#{path}"
auth_sign = sign("PUT", path, content_md5, content_type ,date)
headers = {
"Authorization" => auth_sign,
"Content-Type" => content_type,
"Content-Length" => file.length,
"Date" => date,
- "Host" => "storage.aliyun.com",
+ "Host" => @aliyun_host,
"Expect" => "100-Continue"
}
response = RestClient.put(url, file, headers)
end
@@ -91,11 +95,11 @@
nil
end
end
def url
- "http://storage.aliyun.com/#{@uploader.aliyun_bucket}/#{@path}"
+ "http://oss.aliyuncs.com/#{@uploader.aliyun_bucket}/#{@path}"
end
def store(data)
oss_connection.put(@path, data)
end
@@ -111,16 +115,17 @@
end
def oss_connection
return @oss_connection if @oss_connection
- config = {:aliyun_access_id => @uploader.aliyun_access_id,
+ config = {
+ :aliyun_access_id => @uploader.aliyun_access_id,
:aliyun_access_key => @uploader.aliyun_access_key,
:aliyun_bucket => @uploader.aliyun_bucket
}
@oss_connection ||= CarrierWave::Storage::Aliyun::Connection.new(config)
end
-
+
end
def store!(file)
f = CarrierWave::Storage::Aliyun::File.new(uploader, self, uploader.store_path)
f.store(file.read)