From a70b6f5313ed1a8b1a6afbd16a134b56c9bb0ee1 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Mon, 5 May 2014 20:55:23 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0list=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/qiniu/config.rb | 1 + lib/qiniu/management.rb | 61 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/lib/qiniu/config.rb b/lib/qiniu/config.rb index 7f230e4..1fc7357 100755 --- a/lib/qiniu/config.rb +++ b/lib/qiniu/config.rb @@ -20,6 +20,7 @@ module Qiniu :content_type => 'application/x-www-form-urlencoded', :auth_url => "https://acc.qbox.me/oauth2/token", :rs_host => "http://rs.qiniu.com", + :rsf_host => "http://rsf.qbox.me", :up_host => "http://up.qiniu.com", :pub_host => "http://pu.qbox.me:10200", :eu_host => "http://eu.qbox.me", diff --git a/lib/qiniu/management.rb b/lib/qiniu/management.rb index 300372b..af5a124 100755 --- a/lib/qiniu/management.rb +++ b/lib/qiniu/management.rb @@ -1,10 +1,48 @@ # -*- encoding: utf-8 -*- # vim: sw=2 ts=2 +require 'qiniu/adt' require 'qiniu/http' module Qiniu module Storage + class ListPolicy + include ADT::Policy + + private + def initialize(bucket, + limit = 1000, + prefix = '', + delimiter = '') + @bucket = bucket + @limit = limit + @prefix = prefix + @delimiter = delimiter + end # initialize + + public + PARAMS = { + # 字符串类型参数 + :bucket => "bucket", + :prefix => "prefix", + :delimiter => "delimiter", + :marker => "marker", + + # 数值类型参数 + :limit => "limit" + } # PARAMS + + PARAMS.each_pair do |key, fld| + attr_accessor key + end + + def params + return PARAMS + end # params + + alias :to_s :to_query_string + end # class ListPolicy + class << self include Utils @@ -107,6 +145,26 @@ module Qiniu save_as(bucket, key, source_image_url, mogrify_params_string) end # image_mogrify_save_as + def list(list_policy) + url = Config.settings[:rsf_host] + '/list?' + list_policy.to_query_string() + + resp_code, resp_body, resp_headers = HTTP.management_post(url) + if resp_code == 0 || resp_code > 299 then + has_more = false + return resp_code, resp_body, resp_headers, has_more, list_policy + end + + has_more = (resp_body['marker'].is_a?(String) && resp_body['marker'] != '') + if has_more then + new_list_policy = list_policy.clone() + new_list_policy.marker = resp_body['marker'] + else + new_list_policy = list_policy + end + + return resp_code, resp_body, resp_headers, has_more, new_list_policy + end # list + private def _generate_cp_or_mv_opstr(command, source_bucket, source_key, target_bucket, target_key) @@ -123,6 +181,7 @@ module Qiniu url = Config.settings[:rs_host] + "/batch" return HTTP.management_post(url, execs.join("&")) end # _batch_cp_or_mv - end + + end # class << self end # module Storage end # module Qiniu From 804fa4d5b63ac2d7c140e6328cbf8a0e41ffe160 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Fri, 1 Aug 2014 17:08:05 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0rsf=5Fhost=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/qiniu/config.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/qiniu/config.rb b/lib/qiniu/config.rb index ac59b99..bd1f3d6 100755 --- a/lib/qiniu/config.rb +++ b/lib/qiniu/config.rb @@ -20,6 +20,7 @@ module Qiniu :content_type => 'application/x-www-form-urlencoded', :auth_url => "https://acc.qbox.me/oauth2/token", :rs_host => "http://rs.qiniu.com", + :rsf_host => "http://rsf.qbox.me", :up_host => "http://upload.qiniu.com", :pub_host => "http://pu.qbox.me:10200", :eu_host => "http://eu.qbox.me", From b8f43a1dedaba8d88eefa428d3e51c62526f5abf Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Fri, 28 Nov 2014 16:22:58 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=B8=BA=20upload=20=E7=9A=84=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E7=89=88=E6=9C=AC=E6=8E=A5=E5=8F=A3=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20content-type/mimeType=20=E8=AE=BE=E7=BD=AE=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile.lock | 2 +- lib/qiniu/upload.rb | 17 +++++++++++++---- lib/qiniu/version.rb | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) mode change 100755 => 100644 lib/qiniu/upload.rb diff --git a/Gemfile.lock b/Gemfile.lock index e0df932..c162822 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - qiniu (6.3.1) + qiniu (6.4.0) json (~> 1.7) mime-types (~> 1.19) rest-client (~> 1.6) diff --git a/lib/qiniu/upload.rb b/lib/qiniu/upload.rb old mode 100755 new mode 100644 index 4e76eec..c103e1a --- a/lib/qiniu/upload.rb +++ b/lib/qiniu/upload.rb @@ -47,15 +47,23 @@ module Qiniu def upload_with_token_2(uptoken, local_file, key = nil, - x_vars = nil) + x_vars = nil, + opts = {}) ### 构造URL url = Config.settings[:up_host] url[/\/*$/] = '' url += '/' ### 构造HTTP Body + file = File.new(local_file, 'rb') + if not opts[:content_type].nil? + file.define_singleton_method("content_type") do + opts[:content_type] + end + end + post_data = { - :file => File.new(local_file, 'rb'), + :file => file, :multipart => true, } if not uptoken.nil? @@ -84,13 +92,14 @@ module Qiniu def upload_with_put_policy(put_policy, local_file, key = nil, - x_vars = nil) + x_vars = nil, + opts = {}) uptoken = Auth.generate_uptoken(put_policy) if key.nil? then key = put_policy.key end - return upload_with_token_2(uptoken, local_file, key, x_vars) + return upload_with_token_2(uptoken, local_file, key, x_vars, opts) end # upload_with_put_policy private diff --git a/lib/qiniu/version.rb b/lib/qiniu/version.rb index 3fd72d0..2aa467c 100755 --- a/lib/qiniu/version.rb +++ b/lib/qiniu/version.rb @@ -3,8 +3,8 @@ module Qiniu module Version MAJOR = 6 - MINOR = 3 - PATCH = 2 + MINOR = 4 + PATCH = 0 # Returns a version string by joining MAJOR, MINOR, and PATCH with '.' # # Example From f93e50c8383a50b001ae0bdc58933100af0fa676 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Fri, 28 Nov 2014 16:38:47 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ChangeLog=20=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aee5a83..70d1f53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## CHANGE LOG +### v6.4.0 + +- 为 put_with_put_policy() 添加 opts 参数,允许使用 :content_type 键指定上传文件的 mime type。 [https://github.com/qiniu/ruby-sdk/pull/111](https://github.com/qiniu/ruby-sdk/pull/111) + ### v6.3.2 - 调整上传host。 [https://github.com/qiniu/ruby-sdk/pull/103](https://github.com/qiniu/ruby-sdk/pull/103)