Skip to content

Commit 240ec68

Browse files
committed
Merge pull request #86 from coaku/b_xzk_fix_resumable_upload_bug
bug fix
2 parents 3506dff + 906956e commit 240ec68

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

qiniu/auth/up.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
class Client(rpc.Client):
77
up_token = None
8-
8+
99
def __init__(self, up_token, host=None):
1010
if host is None:
1111
host = conf.UP_HOST
12+
if host.startswith("http://"):
13+
host = host[7:]
1214
self.up_token = up_token
1315
super(Client, self).__init__(host)
1416

qiniu/resumable_io.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,14 @@ def put(uptoken, key, f, fsize, extra):
8484
if extra.chunk_size is None:
8585
extra.chunk_size = _chunk_size
8686

87-
client = auth.up.Client(uptoken)
8887
for i in xrange(0, block_cnt):
8988
try_time = extra.try_times
9089
read_length = _block_size
9190
if (i+1)*_block_size > fsize:
9291
read_length = fsize - i*_block_size
9392
data_slice = f.read(read_length)
9493
while True:
95-
err = resumable_block_put(client, data_slice, i, extra)
94+
err = resumable_block_put(data_slice, i, extra, uptoken)
9695
if err is None:
9796
break
9897

@@ -101,34 +100,38 @@ def put(uptoken, key, f, fsize, extra):
101100
return None, err_put_failed
102101
print err, ".. retry"
103102

104-
return mkfile(client, key, fsize, extra)
103+
mkfile_client = auth.up.Client(uptoken, extra.progresses[-1]["host"])
104+
return mkfile(mkfile_client, key, fsize, extra)
105105

106106
# ----------------------------------------------------------
107107

108-
def resumable_block_put(client, block, index, extra):
108+
def resumable_block_put(block, index, extra, uptoken):
109109
block_size = len(block)
110110

111+
mkblk_client = auth.up.Client(uptoken, conf.UP_HOST)
111112
if extra.progresses[index] is None or "ctx" not in extra.progresses[index]:
112113
end_pos = extra.chunk_size-1
113114
if block_size < extra.chunk_size:
114115
end_pos = block_size-1
115116
chunk = block[: end_pos]
116117
crc32 = gen_crc32(chunk)
117118
chunk = bytearray(chunk)
118-
extra.progresses[index], err = mkblock(client, block_size, chunk)
119+
extra.progresses[index], err = mkblock(mkblk_client, block_size, chunk)
119120
if not extra.progresses[index]["crc32"] == crc32:
120121
return err_unmatched_checksum
121122
if err is not None:
122123
extra.notify_err(index, end_pos + 1, err)
123124
return err
124125
extra.notify(index, end_pos + 1, extra.progresses[index])
125126

127+
bput_client = auth.up.Client(uptoken, extra.progresses[index]["host"])
126128
while extra.progresses[index]["offset"] < block_size:
127129
offset = extra.progresses[index]["offset"]
128130
chunk = block[offset: offset+extra.chunk_size-1]
129131
crc32 = gen_crc32(chunk)
130132
chunk = bytearray(chunk)
131-
extra.progresses[index], err = putblock(client, extra.progresses[index], chunk)
133+
134+
extra.progresses[index], err = putblock(bput_client, extra.progresses[index], chunk)
132135
if not extra.progresses[index]["crc32"] == crc32:
133136
return err_unmatched_checksum
134137
if err is not None:

0 commit comments

Comments
 (0)