lib/carrierwave/storage/aliyun.rb in carrierwave-aliyun-0.3.0 vs lib/carrierwave/storage/aliyun.rb in carrierwave-aliyun-0.3.1
- old
+ new
@@ -50,15 +50,31 @@
"Content-Length" => file.size,
"Date" => date,
"Host" => @aliyun_upload_host,
"Expect" => "100-Continue"
}
- RestClient.put(URI.encode(url), file, headers)
+ RestClient.put(URI.encode(url).gsub("+", "%2B"), file, headers)
return path_to_url(path, :get => true)
end
+
=begin rdoc
+读取文件
+
+== 参数:
+- path - remote 存储路径
+
+== 返回值:
+图片文件
+=end
+ def get(path)
+ path = format_path(path)
+ url = path_to_url(path)
+ RestClient.get(URI.encode(url))
+ end
+
+=begin rdoc
删除 Remote 的文件
== 参数:
- path - remote 存储路径
@@ -73,11 +89,11 @@
"Host" => @aliyun_upload_host,
"Date" => date,
"Authorization" => sign("DELETE", bucket_path, "", "" ,date)
}
url = path_to_url(path)
- RestClient.delete(URI.encode(url), headers)
+ RestClient.delete(URI.encode(url).gsub("+", "%2B"), headers)
return path_to_url(path, :get => true)
end
##
# 阿里云需要的 GMT 时间格式
@@ -143,11 +159,12 @@
#
# [String] contents of the file
#
def read
object = oss_connection.get(@path)
- object.data
+ @headers = object.headers
+ object.body
end
##
# Remove the file from Cloud Files
#
@@ -162,9 +179,17 @@
end
end
def url
oss_connection.path_to_url(@path, :get => true)
+ end
+
+ def content_type
+ headers[:content_type]
+ end
+
+ def content_type=(new_content_type)
+ headers[:content_type] = new_content_type
end
def store(file, opts = {})
oss_connection.put(@path, file, opts)
end