add :return_body option for Qiniu::RS.generate_upload_token()

This commit is contained in:
404
2013-01-23 21:30:15 +08:00
parent 84f7cc6205
commit 444956f161
4 changed files with 18 additions and 4 deletions
+7 -2
View File
@@ -126,7 +126,8 @@ title: Ruby SDK 使用指南 | 七牛云存储
:callback_body_type => callback_body_type,
:customer => end_user_id,
:escape => allow_upload_callback_api,
:async_options => async_callback_api_commands
:async_options => async_callback_api_commands,
:return_body => custom_response_body
**参数**
@@ -159,7 +160,11 @@ title: Ruby SDK 使用指南 | 七牛云存储
`foo=bar&w=$(imageInfo.width)&h=$(imageInfo.height)&exif=$(exif)`
:async_options
: 可选,字符串类型(String),用于设置文件上传成功后,执行指定的预转指令。参 [uploadToken 之 asyncOps 说明](http://docs.qiniutek.com/v3/api/io/#uploadToken-asyncOps)
: 可选,字符串类型(String),用于设置文件上传成功后,执行指定的预转指令。参 [uploadToken 之 asyncOps 说明](http://docs.qiniutek.com/v3/api/io/#uploadToken-asyncOps)
:return_body
: 可选,字符串类型(String),用于设置文件上传成功后,执行七牛云存储规定的回调API,并以 JSON 响应格式返回其执行结果。参考 [uploadToken 之 returnBody 说明](/v3/api/io/#uploadToken-returnBody)。
**返回值**
+1
View File
@@ -253,6 +253,7 @@ module Qiniu
#token_obj.customer = opts[:customer]
#token_obj.escape = opts[:escape]
#token_obj.async_options = opts[:async_options]
#token_obj.return_body = opts[:return_body]
token_obj.generate_token
end
+3 -1
View File
@@ -10,7 +10,7 @@ module Qiniu
include Utils
attr_accessor :scope, :expires_in, :callback_url, :callback_body_type, :customer, :escape, :async_options
attr_accessor :scope, :expires_in, :callback_url, :callback_body_type, :customer, :escape, :async_options, :return_body
def initialize(opts = {})
@scope = opts[:scope]
@@ -20,6 +20,7 @@ module Qiniu
@customer = opts[:customer]
@escape = opts[:escape]
@async_options = opts[:async_options]
@return_body = opts[:return_body]
end
def generate_signature
@@ -29,6 +30,7 @@ module Qiniu
params[:customer] = @customer if !@customer.nil? && !@customer.empty?
params[:escape] = 1 if @escape == 1 || @escape == true
params[:asyncOps] = @async_options if !@async_options.nil? && !@async_options.empty?
params[:returnBody] = @return_body if !@return_body.nil? && !@return_body.empty?
Utils.urlsafe_base64_encode(params.to_json)
end
+7 -1
View File
@@ -24,12 +24,18 @@ module Qiniu
:scope => @bucket,
:expires_in => 3600,
:customer => "why404@gmail.com",
:async_options => "imageView/1/w/120/h/120"
:async_options => "imageView/1/w/120/h/120",
:return_body => '{"size":$(fsize), "hash":$(etag), "width":$(imageInfo.width), "height":$(imageInfo.height)}'
}
uptoken = Qiniu::RS.generate_upload_token(upopts)
data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @bucket, :key => @key
puts data.inspect
data["size"].should_not be_zero
data["hash"].should_not be_empty
data["width"].should_not be_zero
data["height"].should_not be_zero
result = Qiniu::RS.get(@bucket, @key)
result["url"].should_not be_empty
puts result.inspect