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) 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/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", diff --git a/lib/qiniu/management.rb b/lib/qiniu/management.rb index b115817..0c07401 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 @@ -86,6 +124,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) @@ -102,6 +160,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 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