From b8f43a1dedaba8d88eefa428d3e51c62526f5abf Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Fri, 28 Nov 2014 16:22:58 +0800 Subject: [PATCH] =?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