@@ -71,12 +71,15 @@ def put_file(uptoken, key, localfile, extra):
71
71
return ret
72
72
73
73
74
- def put (uptoken , key , f , fsize , extra ):
74
+ def put (uptoken , key , f , fsize , extra , host = None ):
75
75
""" 上传二进制流, 通过将data "切片" 分段上传 """
76
76
if not isinstance (extra , PutExtra ):
77
77
print ("extra must the instance of PutExtra" )
78
78
return
79
79
80
+ if host is None :
81
+ host = conf .UP_HOST
82
+
80
83
block_cnt = block_count (fsize )
81
84
if extra .progresses is None :
82
85
extra .progresses = [None ] * block_cnt
@@ -97,7 +100,7 @@ def put(uptoken, key, f, fsize, extra):
97
100
read_length = fsize - i * _block_size
98
101
data_slice = f .read (read_length )
99
102
while True :
100
- err = resumable_block_put (data_slice , i , extra , uptoken )
103
+ err = resumable_block_put (data_slice , i , extra , uptoken , host )
101
104
if err is None :
102
105
break
103
106
@@ -106,19 +109,19 @@ def put(uptoken, key, f, fsize, extra):
106
109
return None , err_put_failed
107
110
print err , ".. retry"
108
111
109
- mkfile_host = extra .progresses [- 1 ]["host" ] if block_cnt else conf . UP_HOST
112
+ mkfile_host = extra .progresses [- 1 ]["host" ] if block_cnt else host
110
113
mkfile_client = auth_up .Client (uptoken , mkfile_host )
111
- return mkfile (mkfile_client , key , fsize , extra )
114
+ return mkfile (mkfile_client , key , fsize , extra , mkfile_host )
112
115
113
116
114
- def resumable_block_put (block , index , extra , uptoken ):
117
+ def resumable_block_put (block , index , extra , uptoken , host ):
115
118
block_size = len (block )
116
119
117
- mkblk_client = auth_up .Client (uptoken , conf . UP_HOST )
120
+ mkblk_client = auth_up .Client (uptoken , host )
118
121
if extra .progresses [index ] is None or "ctx" not in extra .progresses [index ]:
119
122
crc32 = gen_crc32 (block )
120
123
block = bytearray (block )
121
- extra .progresses [index ], err = mkblock (mkblk_client , block_size , block )
124
+ extra .progresses [index ], err = mkblock (mkblk_client , block_size , block , host )
122
125
if err is not None :
123
126
extra .notify_err (index , block_size , err )
124
127
return err
@@ -133,8 +136,8 @@ def block_count(size):
133
136
return (size + _block_mask ) / _block_size
134
137
135
138
136
- def mkblock (client , block_size , first_chunk ):
137
- url = "http://%s/mkblk/%s" % (conf . UP_HOST , block_size )
139
+ def mkblock (client , block_size , first_chunk , host ):
140
+ url = "http://%s/mkblk/%s" % (host , block_size )
138
141
content_type = "application/octet-stream"
139
142
return client .call_with (url , first_chunk , content_type , len (first_chunk ))
140
143
@@ -146,8 +149,8 @@ def putblock(client, block_ret, chunk):
146
149
return client .call_with (url , chunk , content_type , len (chunk ))
147
150
148
151
149
- def mkfile (client , key , fsize , extra ):
150
- url = ["http://%s/mkfile/%s" % (conf . UP_HOST , fsize )]
152
+ def mkfile (client , key , fsize , extra , host ):
153
+ url = ["http://%s/mkfile/%s" % (host , fsize )]
151
154
152
155
if extra .mimetype :
153
156
url .append ("mimeType/%s" % urlsafe_b64encode (extra .mimetype ))
0 commit comments