lib/carrierwave/storage/aliyun.rb in carrierwave-aliyun-0.1.1 vs lib/carrierwave/storage/aliyun.rb in carrierwave-aliyun-0.1.2
- old
+ new
@@ -16,14 +16,14 @@
@aliyun_host = "oss.aliyuncs.com"
if options[:aliyun_internal] == true
@aliyun_host = "oss-internal.aliyuncs.com"
end
end
-
- def put(path, file)
+
+ def put(path, file, options={})
content_md5 = Digest::MD5.hexdigest(file)
- content_type = "image/jpg"
+ content_type = options[:content_type] || "image/jpg"
date = Time.now.gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT")
path = "#{@aliyun_bucket}/#{path}"
url = "http://#{@aliyun_host}/#{path}"
auth_sign = sign("PUT", path, content_md5, content_type ,date)
headers = {
@@ -98,12 +98,12 @@
def url
"http://oss.aliyuncs.com/#{@uploader.aliyun_bucket}/#{@path}"
end
- def store(data)
- oss_connection.put(@path, data)
+ def store(data, opts = {})
+ oss_connection.put(@path, data, opts)
end
private
def headers
@@ -127,10 +127,10 @@
end
def store!(file)
f = CarrierWave::Storage::Aliyun::File.new(uploader, self, uploader.store_path)
- f.store(file.read)
+ f.store(file.read, :content_type => file.content_type)
f
end
def retrieve!(identifier)
CarrierWave::Storage::Aliyun::File.new(uploader, self, uploader.store_path(identifier))