From bacf83dd3c59427ac4bac5d1660ad0ad42f291d0 Mon Sep 17 00:00:00 2001 From: 404 Date: Tue, 6 Nov 2012 22:09:19 +0800 Subject: [PATCH 1/4] allow upload callback api --- docs/README.md | 16 +++++++++++++++- lib/qiniu/rs.rb | 1 + lib/qiniu/rs/version.rb | 2 +- lib/qiniu/tokens/upload_token.rb | 4 +++- spec/qiniu/rs_spec.rb | 6 +++--- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index 00f1e61..5ae1cc5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -120,7 +120,8 @@ title: Ruby SDK 使用指南 | 七牛云存储 :expires_in => expires_in_seconds, :callback_url => callback_url, :callback_body_type => callback_body_type, - :customer => end_user_id + :customer => end_user_id, + :escape => allow_upload_callback_api **参数** @@ -139,6 +140,19 @@ title: Ruby SDK 使用指南 | 七牛云存储 :customer : 可选,字符串类型(String),客户方终端用户(End User)的ID,该字段可以用来标示一个文件的属主,这在一些特殊场景下(比如给终端用户上传的图片打上名字水印)非常有用。 +:escape +: 可选,数字类型,可选值 0 或者 1,缺省为 0 。值为 1 表示 callback 传递的自定义数据中允许存在转义符号 `$(VarExpression)`,参考 [VarExpression](/v3/api/words/#VarExpression)。 + +当 `escape` 的值为 `1` 时,常见的转义语法如下: + +- 若 `callbackBodyType` 为 `application/json` 时,一个典型的自定义回调数据([CallbackParams](/v3/api/io/#CallbackParams))为: + + `{foo: "bar", w: $(imageInfo.width), h: $(imageInfo.height), exif: $(exif)}` + +- 若 `callbackBodyType` 为 `application/x-www-form-urlencoded` 时,一个典型的自定义回调数据([CallbackParams](/v3/api/io/#CallbackParams))为: + + `foo=bar&w=$(imageInfo.width)&h=$(imageInfo.height)&exif=$(exif)` + **返回值** 返回一个字符串类型(String)的用于上传文件用的临时授权 `upload_token`。 diff --git a/lib/qiniu/rs.rb b/lib/qiniu/rs.rb index f826a44..0f70a8d 100755 --- a/lib/qiniu/rs.rb +++ b/lib/qiniu/rs.rb @@ -224,6 +224,7 @@ module Qiniu #token_obj.callback_url = opts[:callback_url] #token_obj.callback_body_type = opts[:callback_body_type] #token_obj.customer = opts[:customer] + #token_obj.escape = opts[:escape] token_obj.generate_token end diff --git a/lib/qiniu/rs/version.rb b/lib/qiniu/rs/version.rb index eb073b7..03918d0 100755 --- a/lib/qiniu/rs/version.rb +++ b/lib/qiniu/rs/version.rb @@ -5,7 +5,7 @@ module Qiniu module Version MAJOR = 3 MINOR = 1 - PATCH = 0 + PATCH = 1 # Returns a version string by joining MAJOR, MINOR, and PATCH with '.' # # Example diff --git a/lib/qiniu/tokens/upload_token.rb b/lib/qiniu/tokens/upload_token.rb index 5fb22b3..bb13af4 100755 --- a/lib/qiniu/tokens/upload_token.rb +++ b/lib/qiniu/tokens/upload_token.rb @@ -10,7 +10,7 @@ module Qiniu include Utils - attr_accessor :scope, :expires_in, :callback_url, :callback_body_type, :customer + attr_accessor :scope, :expires_in, :callback_url, :callback_body_type, :customer, :escape def initialize(opts = {}) @scope = opts[:scope] @@ -18,6 +18,7 @@ module Qiniu @callback_url = opts[:callback_url] @callback_body_type = opts[:callback_body_type] @customer = opts[:customer] + @escape = opts[:escape] end def generate_signature @@ -25,6 +26,7 @@ module Qiniu params[:callbackUrl] = @callback_url if !@callback_url.nil? && !@callback_url.empty? params[:callbackBodyType] = @callback_body_type if !@callback_body_type.nil? && !@callback_body_type.empty? params[:customer] = @customer if !@customer.nil? && !@customer.empty? + params[:escape] = 1 if @escape == 1 || @escape == true urlsafe_base64_encode(params.to_json) end diff --git a/spec/qiniu/rs_spec.rb b/spec/qiniu/rs_spec.rb index 8204b18..a5f3a27 100755 --- a/spec/qiniu/rs_spec.rb +++ b/spec/qiniu/rs_spec.rb @@ -116,7 +116,7 @@ module Qiniu context ".upload_file" do it "should works" do - uptoken_opts = {:scope => @bucket} + uptoken_opts = {:scope => @bucket, :escape => 0} upload_opts = { :uptoken => Qiniu::RS.generate_upload_token(uptoken_opts), :file => __FILE__, @@ -137,7 +137,7 @@ module Qiniu File.open(localfile, "w"){|f| 5242888.times{f.write(Random.rand(9).to_s)}} key = Digest::SHA1.hexdigest(localfile+Time.now.to_s) # generate the upload token - uptoken_opts = {:scope => @bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com"} + uptoken_opts = {:scope => @bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com", :escape => 0} uptoken = Qiniu::RS.generate_upload_token(uptoken_opts) # uploading upload_opts = { @@ -311,7 +311,7 @@ module Qiniu context ".generate_upload_token" do it "should works" do - data = Qiniu::RS.generate_upload_token({:scope => 'test_bucket', :expires_in => 3600}) + data = Qiniu::RS.generate_upload_token({:scope => 'test_bucket', :expires_in => 3600, :escape => 0}) data.should_not be_empty puts data.inspect end From 000eef88707e16a38c73e2dda8bd1c8328195b3b Mon Sep 17 00:00:00 2001 From: 404 Date: Tue, 6 Nov 2012 23:16:40 +0800 Subject: [PATCH 2/4] update unit tests --- Gemfile.lock | 2 +- spec/qiniu/rs/eu_spec.rb | 19 ++++++++++++------- spec/qiniu/rs/image_spec.rb | 36 ++++++++++++++---------------------- spec/qiniu/rs/io_spec.rb | 22 ++++++++++++---------- spec/qiniu/rs/pub_spec.rb | 20 ++++++-------------- spec/qiniu/rs/rs_spec.rb | 14 ++++++++++---- spec/qiniu/rs/up_spec.rb | 12 +++++++++++- spec/qiniu/rs_spec.rb | 28 ++++++++++++++++++++++++---- spec/spec_helper.rb | 5 ----- 9 files changed, 90 insertions(+), 68 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 45c38ca..47939be 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - qiniu-rs (3.1.0) + qiniu-rs (3.1.1) json (~> 1.7) mime-types (~> 1.19) rest-client (~> 1.6) diff --git a/spec/qiniu/rs/eu_spec.rb b/spec/qiniu/rs/eu_spec.rb index 8c6f03f..ff7558e 100755 --- a/spec/qiniu/rs/eu_spec.rb +++ b/spec/qiniu/rs/eu_spec.rb @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- require 'spec_helper' -require 'qiniu/rs/io' +require 'qiniu/rs' require 'qiniu/rs/pub' require 'qiniu/rs/eu' @@ -14,12 +14,15 @@ module Qiniu @bucket = "wm_test_bucket" @key = "image_logo_for_test.png" + result = Qiniu::RS.mkbucket(@bucket) + puts result.inspect + result.should be_true + local_file = File.expand_path('../' + @key, __FILE__) upopts = {:scope => @bucket, :expires_in => 3600, :customer => @customer_id} uptoken = Qiniu::RS.generate_upload_token(upopts) - code, data = Qiniu::RS::IO.upload_with_token(uptoken, local_file, @bucket, @key, nil, nil, nil, true) - code.should == 200 + data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @bucket, :key => @key puts data.inspect code2, data2 = Qiniu::RS::Pub.set_separator(@bucket, "-") @@ -31,10 +34,12 @@ module Qiniu puts data3.inspect end - #after :all do - # result = Qiniu::RS.drop(@bucket) - # result.should_not be_false - #end + after :all do + @bucket = "wm_test_bucket" + result = Qiniu::RS.drop(@bucket) + puts result.inspect + result.should_not be_false + end context ".set_watermark" do it "should works" do diff --git a/spec/qiniu/rs/image_spec.rb b/spec/qiniu/rs/image_spec.rb index c01ab00..b65f463 100755 --- a/spec/qiniu/rs/image_spec.rb +++ b/spec/qiniu/rs/image_spec.rb @@ -10,35 +10,20 @@ module Qiniu describe Image do before :all do -=begin - code, data = Qiniu::RS::Auth.exchange_by_password!("test@qbox.net", "test") - code.should == 200 - data.should be_an_instance_of(Hash) - data["access_token"].should_not be_empty - data["refresh_token"].should_not be_empty - data["refresh_token"].should_not be_empty - puts data.inspect -=end @bucket = "test_images_12345" @key = "image_logo_for_test.png" - local_file = File.expand_path('../' + @key, __FILE__) - - result = Qiniu::RS.drop(@bucket) - result.should_not be_false + result = Qiniu::RS.mkbucket(@bucket) puts result.inspect - - put_url = Qiniu::RS.put_auth(10) - put_url.should_not be_false - put_url.should_not be_empty - result = Qiniu::RS.upload :url => put_url, - :file => local_file, - :bucket => @bucket, - :key => @key, - :enable_crc32_check => true result.should be_true + local_file = File.expand_path('../' + @key, __FILE__) + + upopts = {:scope => @bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com"} + uptoken = Qiniu::RS.generate_upload_token(upopts) + data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @bucket, :key => @key + puts data.inspect result = Qiniu::RS.get(@bucket, @key) result["url"].should_not be_empty @@ -56,6 +41,13 @@ module Qiniu } end + after :all do + @bucket = "test_images_12345" + result = Qiniu::RS.drop(@bucket) + puts result.inspect + result.should_not be_false + end + context ".info" do it "should works" do code, data = Qiniu::RS::Image.info(@source_image_url) diff --git a/spec/qiniu/rs/io_spec.rb b/spec/qiniu/rs/io_spec.rb index ac80a4a..70abd7f 100755 --- a/spec/qiniu/rs/io_spec.rb +++ b/spec/qiniu/rs/io_spec.rb @@ -10,17 +10,19 @@ module Qiniu describe IO do before :all do -=begin - code, data = Qiniu::RS::Auth.exchange_by_password!("test@qbox.net", "test") - code.should == 200 - data.should be_an_instance_of(Hash) - data["access_token"].should_not be_empty - data["refresh_token"].should_not be_empty - data["refresh_token"].should_not be_empty - puts data.inspect -=end - @bucket = "test" + @bucket = "io_test_bucket" @key = Digest::SHA1.hexdigest (Time.now.to_i+rand(100)).to_s + + result = Qiniu::RS.mkbucket(@bucket) + puts result.inspect + result.should be_true + end + + after :all do + @bucket = "io_test_bucket" + result = Qiniu::RS.drop(@bucket) + puts result.inspect + result.should_not be_false end context ".upload_file" do diff --git a/spec/qiniu/rs/pub_spec.rb b/spec/qiniu/rs/pub_spec.rb index df70e99..3fd3a88 100755 --- a/spec/qiniu/rs/pub_spec.rb +++ b/spec/qiniu/rs/pub_spec.rb @@ -10,24 +10,16 @@ module Qiniu describe Pub do before :all do - @bucket = "test123" - code, data = Qiniu::RS::RS.mkbucket(@bucket) - code.should == 200 - puts data.inspect + @bucket = "pub_test_bucket" + result = Qiniu::RS.mkbucket(@bucket) + puts result.inspect + result.should_not be_false end -=begin - context ".mkbucket" do - it "should works" do - code, data = Qiniu::RS::RS.mkbucket(@bucket) - code.should == 200 - puts data.inspect - end - end -=end - after :all do + @bucket = "pub_test_bucket" result = Qiniu::RS.drop(@bucket) + puts result.inspect result.should_not be_false end diff --git a/spec/qiniu/rs/rs_spec.rb b/spec/qiniu/rs/rs_spec.rb index ec8e936..101916d 100755 --- a/spec/qiniu/rs/rs_spec.rb +++ b/spec/qiniu/rs/rs_spec.rb @@ -11,13 +11,19 @@ module Qiniu describe RS do before :all do - - @bucket = "test_bucket_1234" + @bucket = "rs_test_bucket" @key = Digest::SHA1.hexdigest (Time.now.to_i+rand(100)).to_s - @domain = 'iovip.qbox.me/test' + @domain = 'rs-test-bucket.dn.qbox.me' code, data = Qiniu::RS::RS.mkbucket(@bucket) - puts data.inspect + puts [code, data].inspect + code.should == 200 + end + + after :all do + @bucket = "rs_test_bucket" + code, data = Qiniu::RS::RS.drop(@bucket) + puts [code, data].inspect code.should == 200 end diff --git a/spec/qiniu/rs/up_spec.rb b/spec/qiniu/rs/up_spec.rb index ccd623e..a0e12c9 100755 --- a/spec/qiniu/rs/up_spec.rb +++ b/spec/qiniu/rs/up_spec.rb @@ -12,12 +12,22 @@ module Qiniu before :all do @localfile = "bigfile.txt" File.open(@localfile, "w"){|f| 9437184.times{f.write(Random.rand(9).to_s)}} - @bucket = "test" + @bucket = "up_test_bucket" @key = Digest::SHA1.hexdigest(@localfile+Time.now.to_s) + + code, data = Qiniu::RS::RS.mkbucket(@bucket) + puts [code, data].inspect + code.should == 200 end after :all do + @localfile = "bigfile.txt" File.unlink(@localfile) if File.exists?(@localfile) + + @bucket = "up_test_bucket" + code, data = Qiniu::RS::RS.drop(@bucket) + puts [code, data].inspect + code.should == 200 end context ".upload_with_token" do diff --git a/spec/qiniu/rs_spec.rb b/spec/qiniu/rs_spec.rb index a5f3a27..39c94c8 100755 --- a/spec/qiniu/rs_spec.rb +++ b/spec/qiniu/rs_spec.rb @@ -10,13 +10,33 @@ module Qiniu before :all do @bucket = 'qiniu_rs_test' @key = Digest::SHA1.hexdigest Time.now.to_s - @domain = 'cdn.example.com' - - @test_image_bucket = 'test_images_12345' - @test_image_key = 'image_logo_for_test.png' + @domain = 'qiniu-rs-test.dn.qbox.me' result = Qiniu::RS.mkbucket(@bucket) result.should_not be_false + + @test_image_bucket = 'test_images_12345' + result2 = Qiniu::RS.mkbucket(@test_image_bucket) + puts result2.inspect + result2.should be_true + + @test_image_key = 'image_logo_for_test.png' + local_file = File.expand_path('./rs/' + @test_image_key, File.dirname(__FILE__)) + puts local_file.inspect + upopts = {:scope => @test_image_bucket, :expires_in => 3600, :customer => "awhy.xu@gmail.com"} + uptoken = Qiniu::RS.generate_upload_token(upopts) + data = Qiniu::RS.upload_file :uptoken => uptoken, :file => local_file, :bucket => @test_image_bucket, :key => @test_image_key + puts data.inspect + end + + after :all do + result = Qiniu::RS.drop(@bucket) + puts result.inspect + result.should_not be_false + + result2 = Qiniu::RS.drop(@test_image_bucket) + puts result2.inspect + result2.should_not be_false end context ".buckets" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b9fe532..d886e24 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,10 +14,5 @@ RSpec.configure do |config| :up_host => "http://m1.qbox.me:13019", :pub_host => "http://m1.qbox.me:13012", :eu_host => "http://m1.qbox.me:13050" - -=begin - Qiniu::RS.establish_connection! :access_key => "aPoWOtE9EFca1fLxFCtlkeZAOV7aADVMTLdSydmr", - :secret_key => "L3ShtjCQTCagVCDPfHJoOix7JO_o3qHz3ScyflUG" -=end end end From ef1739cb2a67cf9e60e5cb70a53c9ed95fcd431b Mon Sep 17 00:00:00 2001 From: 404 Date: Tue, 6 Nov 2012 23:19:14 +0800 Subject: [PATCH 3/4] v3.2.0 --- Gemfile.lock | 2 +- lib/qiniu/rs/version.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 47939be..afce319 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - qiniu-rs (3.1.1) + qiniu-rs (3.2.0) json (~> 1.7) mime-types (~> 1.19) rest-client (~> 1.6) diff --git a/lib/qiniu/rs/version.rb b/lib/qiniu/rs/version.rb index 03918d0..e2f7b70 100755 --- a/lib/qiniu/rs/version.rb +++ b/lib/qiniu/rs/version.rb @@ -4,8 +4,8 @@ module Qiniu module RS module Version MAJOR = 3 - MINOR = 1 - PATCH = 1 + MINOR = 2 + PATCH = 0 # Returns a version string by joining MAJOR, MINOR, and PATCH with '.' # # Example From bb6efd4e0d6f621be4f111840bd575e5c31cc975 Mon Sep 17 00:00:00 2001 From: 404 Date: Wed, 7 Nov 2012 17:28:48 +0800 Subject: [PATCH 4/4] upload auto-rorate supported --- Gemfile.lock | 2 +- docs/NEWS.md | 25 +++++++++++++++++++++++++ docs/README.md | 6 +++++- lib/qiniu/rs.rb | 6 ++++-- lib/qiniu/rs/io.rb | 7 ++++--- lib/qiniu/rs/up.rb | 14 ++++++++------ lib/qiniu/rs/version.rb | 2 +- 7 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 docs/NEWS.md diff --git a/Gemfile.lock b/Gemfile.lock index afce319..badf1cd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - qiniu-rs (3.2.0) + qiniu-rs (3.2.1) json (~> 1.7) mime-types (~> 1.19) rest-client (~> 1.6) diff --git a/docs/NEWS.md b/docs/NEWS.md new file mode 100644 index 0000000..a2e60f2 --- /dev/null +++ b/docs/NEWS.md @@ -0,0 +1,25 @@ +## CHANGE LOG + +### v3.2.1 + +allow images uploaded auto-orient. + +允许图片上传成功后自动旋转。 + +参考: + +1. [[API] multipart/form-data 上传文件之 action 字段详解](http://docs.qiniutek.com/v3/api/io/#upload-action) +2. [[SDK] Qiniu::RS.upload_file() 方法中的参数增加了 :rotate 选项](http://docs.qiniutek.com/v3/sdk/ruby/#upload-server-side) + +### v3.2.0 + +2012-11-06 + +allow files uploaded auto callback some APIs (like imageInfo, exif, etc…), and add those APIs callback results as part of the custom data for POST biz-server. + +允许上传文件(图片)成功后执行回调指定的 API (比如 imageInfo, exif 接口等),并将指定API的回调结果一并 POST 发送给客户方的业务服务器。 + +参考: + +1. [[API] 生成上传授权凭证 uploadToken 之 escape 参数详解](http://docs.qiniutek.com/v3/api/io/#escape-expression) +2. [[SDK] Qiniu::RS.generate_upload_token() 方法中的参数增加了 :escape 选项](http://docs.qiniutek.com/v3/sdk/ruby/#generate-upload-token) \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 5ae1cc5..5421375 100644 --- a/docs/README.md +++ b/docs/README.md @@ -170,7 +170,8 @@ title: Ruby SDK 使用指南 | 七牛云存储 :mime_type => file_mime_type, :note => some_notes, :callback_params => callback_params, - :enable_crc32_check => false + :enable_crc32_check => false, + :rotate => auto_rotate **参数** @@ -198,6 +199,9 @@ title: Ruby SDK 使用指南 | 七牛云存储 :enable_crc32_check : 可选,Boolean 类型,是否启用文件上传 crc32 校验,缺省为 false 。 +:rotate +: 可选,数字类型,上传图片时专用,可针对图片上传后进行旋转。该参数值为 0 :表示根据图像EXIF信息自动旋转;值为 1 : 右转90度;值为 2 :右转180度;值为 3 : 右转270度。 + **返回值** 上传成功,返回如下一个 Hash: diff --git a/lib/qiniu/rs.rb b/lib/qiniu/rs.rb index 0f70a8d..d714708 100755 --- a/lib/qiniu/rs.rb +++ b/lib/qiniu/rs.rb @@ -114,7 +114,8 @@ module Qiniu opts[:mime_type], opts[:note], opts[:customer], - opts[:callback_params]) + opts[:callback_params], + opts[:rotate]) else code, data = IO.upload_with_token(opts[:uptoken], opts[:file], @@ -123,7 +124,8 @@ module Qiniu opts[:mime_type], opts[:note], opts[:callback_params], - opts[:enable_crc32_check]) + opts[:enable_crc32_check], + opts[:rotate]) end raise UploadFailedError.new(code, data) if code != StatusOK return data diff --git a/lib/qiniu/rs/io.rb b/lib/qiniu/rs/io.rb index 36d05cc..cccabe3 100755 --- a/lib/qiniu/rs/io.rb +++ b/lib/qiniu/rs/io.rb @@ -34,8 +34,8 @@ module Qiniu Auth.request url, ::IO.read(local_file), options end - def upload_with_token(uptoken, local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, callback_params = nil, enable_crc32_check = false) - action_params = _generate_action_params(local_file, bucket, key, mime_type, custom_meta, enable_crc32_check) + def upload_with_token(uptoken, local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, callback_params = nil, enable_crc32_check = false, rotate = nil) + action_params = _generate_action_params(local_file, bucket, key, mime_type, custom_meta, enable_crc32_check, rotate) callback_params = {:bucket => bucket, :key => key, :mime_type => mime_type} if callback_params.nil? callback_query_string = Utils.generate_query_string(callback_params) url = Config.settings[:up_host] + '/upload' @@ -43,7 +43,7 @@ module Qiniu end private - def _generate_action_params(local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, enable_crc32_check = false) + def _generate_action_params(local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, enable_crc32_check = false, rotate = nil) raise NoSuchFileError, local_file unless File.exist?(local_file) key = Digest::SHA1.hexdigest(local_file + Time.now.to_s) if key.nil? entry_uri = bucket + ':' + key @@ -54,6 +54,7 @@ module Qiniu action_params = '/rs-put/' + Utils.urlsafe_base64_encode(entry_uri) + '/mimeType/' + Utils.urlsafe_base64_encode(mime_type) action_params += '/meta/' + Utils.urlsafe_base64_encode(custom_meta) unless custom_meta.nil? action_params += '/crc32/' + Utils.crc32checksum(local_file).to_s if enable_crc32_check + action_params += '/rotate/' + rotate if !rotate.nil? && rotate.to_i >= 0 action_params end diff --git a/lib/qiniu/rs/up.rb b/lib/qiniu/rs/up.rb index c54dbd4..5a02ea0 100755 --- a/lib/qiniu/rs/up.rb +++ b/lib/qiniu/rs/up.rb @@ -115,7 +115,8 @@ module Qiniu mime_type = nil, custom_meta = nil, customer = nil, - callback_params = nil) + callback_params = nil, + rotate = nil) raise NoSuchFileError, local_file unless File.exist?(local_file) begin ifile = File.open(local_file, 'rb') @@ -127,9 +128,9 @@ module Qiniu mime_type = mime.empty? ? 'application/octet-stream' : mime[0].content_type end if fsize > Config.settings[:block_size] - code, data = _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type, custom_meta, customer, callback_params) + code, data = _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type, custom_meta, customer, callback_params, rotate) else - code, data = IO.upload_with_token(uptoken, local_file, bucket, key, mime_type, custom_meta, callback_params, true) + code, data = IO.upload_with_token(uptoken, local_file, bucket, key, mime_type, custom_meta, callback_params, true, rotate) end [code, data] ensure @@ -289,13 +290,14 @@ module Qiniu return [code, data] end - def _mkfile(uptoken, entry_uri, fsize, checksums, mime_type = nil, custom_meta = nil, customer = nil, callback_params = nil) + def _mkfile(uptoken, entry_uri, fsize, checksums, mime_type = nil, custom_meta = nil, customer = nil, callback_params = nil, rotate = nil) path = '/rs-mkfile/' + Utils.urlsafe_base64_encode(entry_uri) + "/fsize/#{fsize}" path += '/mimeType/' + Utils.urlsafe_base64_encode(mime_type) if !mime_type.nil? && !mime_type.empty? path += '/meta/' + Utils.urlsafe_base64_encode(custom_meta) if !custom_meta.nil? && !custom_meta.empty? path += '/customer/' + customer if !customer.nil? && !customer.empty? callback_query_string = Utils.generate_query_string(callback_params) if !callback_params.nil? && !callback_params.empty? path += '/params/' + Utils.urlsafe_base64_encode(callback_query_string) if !callback_query_string.nil? && !callback_query_string.empty? + path += '/rotate/' + rotate if !rotate.nil? && rotate.to_i >= 0 url = Config.settings[:up_host] + path body = '' checksums.each do |checksum| @@ -304,7 +306,7 @@ module Qiniu _call_binary_with_token(uptoken, url, body) end - def _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type = nil, custom_meta = nil, customer = nil, callback_params = nil) + def _resumable_upload(uptoken, fh, fsize, bucket, key, mime_type = nil, custom_meta = nil, customer = nil, callback_params = nil, rotate = nil) block_count = _block_count(fsize) progress_data = ProgressData.new(key) checksums = progress_data.get_checksums @@ -322,7 +324,7 @@ module Qiniu code, data = _resumable_put(uptoken, fh, checksums, progresses, block_notifier, chunk_notifier) if Utils.is_response_ok?(code) entry_uri = bucket + ':' + key - code, data = _mkfile(uptoken, entry_uri, fsize, checksums, mime_type, custom_meta, customer, callback_params) + code, data = _mkfile(uptoken, entry_uri, fsize, checksums, mime_type, custom_meta, customer, callback_params, rotate) end if Utils.is_response_ok?(code) Utils.debug "File #{fh.path} {size: #{fsize}} successfully uploaded." diff --git a/lib/qiniu/rs/version.rb b/lib/qiniu/rs/version.rb index e2f7b70..39161dc 100755 --- a/lib/qiniu/rs/version.rb +++ b/lib/qiniu/rs/version.rb @@ -5,7 +5,7 @@ module Qiniu module Version MAJOR = 3 MINOR = 2 - PATCH = 0 + PATCH = 1 # Returns a version string by joining MAJOR, MINOR, and PATCH with '.' # # Example