@@ -479,6 +479,7 @@ def get_presigned_url(self, Bucket, Key, Method, Expired=300, Params={}, Headers
479479 """
480480 url = self ._conf .uri (bucket = Bucket , path = Key )
481481 sign = self .get_auth (Method = Method , Bucket = Bucket , Key = Key , Expired = Expired , Headers = Headers , Params = Params )
482+ sign = urlencode (dict ([item .split ('=' , 1 ) for item in sign .split ('&' )]))
482483 url = url + '?' + sign
483484 if Params :
484485 url = url + '&' + urlencode (Params )
@@ -2828,7 +2829,7 @@ def list_buckets(self, **kwargs):
28282829 return data
28292830
28302831 # Advanced interface
2831- def _upload_part (self , bucket , key , local_path , offset , size , part_num , uploadid , md5_lst , resumable_flag , already_exist_parts , enable_md5 ):
2832+ def _upload_part (self , bucket , key , local_path , offset , size , part_num , uploadid , md5_lst , resumable_flag , already_exist_parts , enable_md5 , traffic_limit ):
28322833 """从本地文件中读取分块, 上传单个分块,将结果记录在md5——list中
28332834
28342835 :param bucket(string): 存储桶名称.
@@ -2851,7 +2852,7 @@ def _upload_part(self, bucket, key, local_path, offset, size, part_num, uploadid
28512852 with open (local_path , 'rb' ) as fp :
28522853 fp .seek (offset , 0 )
28532854 data = fp .read (size )
2854- rt = self .upload_part (bucket , key , data , part_num , uploadid , enable_md5 )
2855+ rt = self .upload_part (bucket , key , data , part_num , uploadid , enable_md5 , TrafficLimit = traffic_limit )
28552856 md5_lst .append ({'PartNumber' : part_num , 'ETag' : rt ['ETag' ]})
28562857 return None
28572858
@@ -3004,15 +3005,19 @@ def upload_file(self, Bucket, Key, LocalFilePath, PartSize=1, MAXThread=5, Enabl
30043005 logger .info ("create a new uploadid in upload_file, uploadid={uploadid}" .format (uploadid = uploadid ))
30053006
30063007 # 上传分块
3008+ # 增加限速功能
3009+ traffic_limit = None
3010+ if 'TrafficLimit' in kwargs :
3011+ traffic_limit = kwargs ['TrafficLimit' ]
30073012 offset = 0 # 记录文件偏移量
30083013 lst = list () # 记录分块信息
30093014 pool = SimpleThreadPool (MAXThread )
30103015
30113016 for i in range (1 , parts_num + 1 ):
30123017 if i == parts_num : # 最后一块
3013- pool .add_task (self ._upload_part , Bucket , Key , LocalFilePath , offset , file_size - offset , i , uploadid , lst , resumable_flag , already_exist_parts , EnableMD5 )
3018+ pool .add_task (self ._upload_part , Bucket , Key , LocalFilePath , offset , file_size - offset , i , uploadid , lst , resumable_flag , already_exist_parts , EnableMD5 , traffic_limit )
30143019 else :
3015- pool .add_task (self ._upload_part , Bucket , Key , LocalFilePath , offset , part_size , i , uploadid , lst , resumable_flag , already_exist_parts , EnableMD5 )
3020+ pool .add_task (self ._upload_part , Bucket , Key , LocalFilePath , offset , part_size , i , uploadid , lst , resumable_flag , already_exist_parts , EnableMD5 , traffic_limit )
30163021 offset += part_size
30173022
30183023 pool .wait_completion ()
0 commit comments