Compare commits

..
6 Commits
Author SHA1 Message Date
xushiwei 2bbcfff82f Merge pull request #11 from why404/master
fixed Qiniu::RS.put_file() 401
2012-07-28 05:09:30 -07:00
404 b2b5b8b92d added Qiniu::RS::Image.exif() 2012-07-28 19:06:35 +08:00
404 e5c57d4d72 fixed put_file 401 2012-07-28 16:20:41 +08:00
404 9ff7228a8f fix put_file 401 2012-07-28 16:19:08 +08:00
xushiwei abadfe65ba Merge pull request #10 from why404/master
fixed Qiniu::RS.put_file()
2012-07-28 00:28:50 -07:00
404 006df109a7 fixed Qiniu::RS.put_file() 2012-07-28 15:16:26 +08:00
10 changed files with 65 additions and 55 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
qiniu-rs (2.3.0)
qiniu-rs (2.3.3)
json (~> 1.7.3)
mime-types (~> 1.19)
rest-client (~> 1.6.7)
@@ -12,7 +12,7 @@ GEM
specs:
diff-lcs (1.1.3)
fakeweb (1.3.0)
json (1.7.3)
json (1.7.4)
mime-types (1.19)
rake (0.9.2.2)
rest-client (1.6.7)
+22 -2
View File
@@ -31,6 +31,7 @@ title: Ruby SDK 使用指南 | 七牛云存储
- [取消公开外链](#unpublish)
- [图像处理](#op-image)
- [查看图片属性信息](#image_info)
- [查看图片EXIF信息](#image_exif)
- [获取指定规格的缩略图预览地址](#image_preview_url)
- [高级图像处理(缩略、裁剪、旋转、转化)](#image_mogrify_preview_url)
- [高级图像处理(缩略、裁剪、旋转、转化)并持久化](#image_mogrify_save_as)
@@ -484,6 +485,24 @@ height
colorModel
: 原始图片着色模式
<a name="image_exif"></a>
#### 查看图片EXIF信息
Qiniu::RS.image_exif(url)
使用 SDK 提供的 `Qiniu::RS.image_exif` 方法,可以基于一张存储于七牛云存储服务器上的原始图片图片,取到该图片的 EXIF 信息。
**参数**
url
: 必须,字符串类型(String),原图的下载链接,需是 `Qiniu::RS.get`(或`Qiniu::RS.batch_get`)函数返回值中 `url` 字段的值,或者是 `Qiniu::RS.download`(或`Qiniu::RS.batch_download`)函数返回的下载链接。且文件本身必须是图片。
**返回值**
如果参数 `url` 所代表的图片没有 EXIF 信息,返回 `false`。否则,返回一个包含 EXIF 信息的 Hash 结构。
<a name="image_preview_url"></a>
#### 获取指定规格的缩略图预览地址
@@ -505,6 +524,7 @@ spec
返回一个字符串类型的缩略图 URL
<a name="image_mogrify_preview_url"></a>
#### 高级图像处理(缩略、裁剪、旋转、转化)
@@ -533,7 +553,7 @@ mogrify_options
:auto_orient => <TrueOrFalse>
}
`Qiniu::RS.image_mogrify_preview_url()` 方法是对七牛云存储图像处理高级接口的完整包装,关于 `mogrify_options` 参数里边的具体含义和使用方式,可以参考文档:[图像处理高级接口](#/v2/api/foimg/#fo-imageMogr)。
`Qiniu::RS.image_mogrify_preview_url()` 方法是对七牛云存储图像处理高级接口的完整包装,关于 `mogrify_options` 参数里边的具体含义和使用方式,可以参考文档:[图像处理高级接口](/v2/api/foimg/#fo-imageMogr)。
**返回值**
@@ -574,7 +594,7 @@ mogrify_options
:auto_orient => <TrueOrFalse>
}
`Qiniu::RS::Image.mogrify_preview_url()` 方法是对七牛云存储图像处理高级接口的完整包装,关于 `mogrify_options` 参数里边的具体含义和使用方式,可以参考文档:[图像处理高级接口](#/v2/api/foimg/#fo-imageMogr)。
`Qiniu::RS::Image.mogrify_preview_url()` 方法是对七牛云存储图像处理高级接口的完整包装,关于 `mogrify_options` 参数里边的具体含义和使用方式,可以参考文档:[图像处理高级接口](/v2/api/foimg/#fo-imageMogr)。
**返回值**
+5
View File
@@ -124,6 +124,11 @@ module Qiniu
code == StatusOK ? data : false
end
def image_exif(url)
code, data = Image.exif(url)
code == StatusOK ? data : false
end
def image_preview_url(url, spec)
Image.preivew_url(url, spec)
end
+4 -4
View File
@@ -58,17 +58,17 @@ module Qiniu
[code, data]
end
def call_with_signature(url, data, retry_times = 0)
code, data = http_request url, data, {:qbox_signature_token => generate_qbox_signature(url, data)}
def call_with_signature(url, data, retry_times = 0, options = {})
code, data = http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data)})
[code, data]
end
def request(url, data = nil)
def request(url, data = nil, options = {})
begin
if Config.settings[:access_key].empty? || Config.settings[:secret_key].empty?
code, data = Auth.call_with_logged_in(url, data)
else
code, data = Auth.call_with_signature(url, data)
code, data = Auth.call_with_signature(url, data, 0, options)
end
rescue [MissingAccessToken, MissingRefreshToken, MissingUsernameOrPassword] => e
Log.logger.error e
+5 -1
View File
@@ -10,6 +10,10 @@ module Qiniu
Utils.http_request url + '/imageInfo', nil, {:method => :get}
end
def exif(url)
Utils.http_request url + '?exif', nil, {:method => :get}
end
def preivew_url(url, spec)
url + '/imagePreview/' + spec.to_s
end
@@ -29,7 +33,7 @@ module Qiniu
params_string += %Q(/#{key}/#{opts[key]}) unless opts[key].nil?
end
params_string += '/auto-orient' unless opts["auto_orient"].nil?
'imageMogr' + params_string
'imageMogr' + URI.escape(params_string)
end
end
+2 -3
View File
@@ -30,9 +30,8 @@ module Qiniu
def put_file(local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, enable_crc32_check = false)
action_params = _generate_action_params(local_file, bucket, key, mime_type, custom_meta, enable_crc32_check)
url = Config.settings[:io_host] + action_params
post_data = {:file => File.new(local_file, 'rb'), :multipart => true}
options = {:qbox_signature_token => Utils.generate_qbox_signature(url, nil)}
Utils.send_multipart_request url, post_data, options
options = {:content_type => 'application/octet-stream'}
Auth.request url, ::IO.read(local_file), options
end
private
+4 -39
View File
@@ -49,10 +49,10 @@ module Qiniu
header_options.merge!('Authorization' => auth_token) unless auth_token.nil?
case options[:method]
when :get
response = RestClient.get url, header_options
response = RestClient.get(url, header_options)
when :post
header_options.merge!(:content_type => options[:content_type])
response = RestClient.post url, data, header_options
response = RestClient.post(url, data, header_options)
end
code = response.respond_to?(:code) ? response.code.to_i : 0
if code != 200
@@ -91,49 +91,14 @@ module Qiniu
end
end
def send_multipart_request(url, post_data, options = {})
code, data = 0, {}
begin
header_options = {
:accept => :json,
:user_agent => Config.settings[:user_agent]
}
auth_token = nil
if !options[:qbox_signature_token].nil? && !options[:qbox_signature_token].empty?
auth_token = 'QBox ' + options[:qbox_signature_token]
#elsif !options[:upload_signature_token].nil? && !options[:upload_signature_token].empty?
#auth_token = 'UpToken ' + options[:upload_signature_token]
elsif options[:access_token]
auth_token = 'Bearer ' + options[:access_token]
end
header_options.merge!('Authorization' => auth_token) unless auth_token.nil?
response = RestClient.post url, post_data, header_options
body = response.respond_to?(:body) ? response.body : ""
data = safe_json_parse(body) unless body.empty?
code = response.code.to_i if response.respond_to?(:code)
rescue Errno::ECONNRESET => err
Log.logger.error err
rescue => e
Log.logger.warn "#{e.message} => Utils.http_request('#{url}')"
res = e.response
if e.respond_to? :response
res = e.response
code = res.code.to_i if res.respond_to? :code
body = res.respond_to?(:body) ? res.body : ""
data = safe_json_parse(body) unless body.empty?
end
end
[code, data]
end
def upload_multipart_data(url, filepath, action_string, callback_query_string = '')
post_data = {
:file => File.new(filepath, 'rb'),
:params => callback_query_string,
:action => action_string,
:file => File.new(filepath, 'rb'),
:multipart => true
}
send_multipart_request(url, post_data)
http_request url, post_data
end
def generate_query_string(params)
+1 -1
View File
@@ -2,6 +2,6 @@
module Qiniu
module RS
VERSION = "2.3.0"
VERSION = "2.3.3"
end
end
+8 -2
View File
@@ -36,7 +36,6 @@ module Qiniu
:file => local_file,
:bucket => @bucket,
:key => @key,
:mime_type => "image/png",
:enable_crc32_check => true
result.should be_true
@@ -47,7 +46,7 @@ module Qiniu
@source_image_url = result["url"]
@mogrify_options = {
:thumbnail => "!120x120r",
:thumbnail => "!120x120>",
:gravity => "center",
:crop => "!120x120a0a0",
:quality => 85,
@@ -65,6 +64,13 @@ module Qiniu
end
end
context ".exif" do
it "should works" do
code, data = Qiniu::RS::Image.exif(@source_image_url)
puts data.inspect
end
end
context ".mogrify_preview_url" do
it "should works" do
mogrify_preview_url = Qiniu::RS::Image.mogrify_preview_url(@source_image_url, @mogrify_options)
+12 -1
View File
@@ -164,6 +164,17 @@ module Qiniu
end
end
context ".image_exif" do
it "should works" do
data = Qiniu::RS.get(@test_image_bucket, @test_image_key)
data.should_not be_false
data.should_not be_empty
puts data.inspect
result = Qiniu::RS.image_exif(data["url"])
puts result.inspect
end
end
context ".image_mogrify_save_as" do
it "should works" do
data = Qiniu::RS.get(@test_image_bucket, @test_image_key)
@@ -175,7 +186,7 @@ module Qiniu
dest_key = "cropped-" + @test_image_key
src_img_url = data["url"]
mogrify_options = {
:thumbnail => "!120x120r",
:thumbnail => "!120x120>",
:gravity => "center",
:crop => "!120x120a0a0",
:quality => 85,