From 4db869a53a4f6545cf06dc859132c3c301e56606 Mon Sep 17 00:00:00 2001 From: Junv Date: Mon, 21 Mar 2016 16:16:43 +0800 Subject: [PATCH] Support file steam to upload --- lib/qiniu/upload.rb | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/qiniu/upload.rb b/lib/qiniu/upload.rb index c103e1a..549001b 100644 --- a/lib/qiniu/upload.rb +++ b/lib/qiniu/upload.rb @@ -49,13 +49,22 @@ module Qiniu key = nil, x_vars = nil, opts = {}) + + file = File.new(local_file, 'rb') + return upload_with_token_2_file_stream(uptoken, file, key, x_vars, opts) + end # upload_with_token_2 + + def upload_with_token_2_file_stream(uptoken, + file, + key = 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] @@ -63,8 +72,8 @@ module Qiniu end post_data = { - :file => file, - :multipart => true, + :file => file, + :multipart => true, } if not uptoken.nil? post_data[:token] = uptoken @@ -78,7 +87,7 @@ module Qiniu ### 发送请求 HTTP.api_post(url, post_data) - end # upload_with_token_2 + end ### 授权举例 # put_policy.bucket | put_policy.key | key | 语义 | 授权