Permalink
Browse files

Merge pull request #86 from coaku/b_xzk_fix_resumable_upload_bug

bug fix
  • Loading branch information...
2 parents 3506dff + 906956e commit 240ec6894f49384410005a4d8a111022c3232de7 @xushiwei xushiwei committed Dec 23, 2013
Showing with 12 additions and 7 deletions.
  1. +3 −1 qiniu/auth/up.py
  2. +9 −6 qiniu/resumable_io.py
View
4 qiniu/auth/up.py
@@ -5,10 +5,12 @@
class Client(rpc.Client):
up_token = None
-
+
def __init__(self, up_token, host=None):
if host is None:
host = conf.UP_HOST
+ if host.startswith("http://"):
+ host = host[7:]
self.up_token = up_token
super(Client, self).__init__(host)
View
15 qiniu/resumable_io.py
@@ -84,15 +84,14 @@ def put(uptoken, key, f, fsize, extra):
if extra.chunk_size is None:
extra.chunk_size = _chunk_size
- client = auth.up.Client(uptoken)
for i in xrange(0, block_cnt):
try_time = extra.try_times
read_length = _block_size
if (i+1)*_block_size > fsize:
read_length = fsize - i*_block_size
data_slice = f.read(read_length)
while True:
- err = resumable_block_put(client, data_slice, i, extra)
+ err = resumable_block_put(data_slice, i, extra, uptoken)
if err is None:
break
@@ -101,34 +100,38 @@ def put(uptoken, key, f, fsize, extra):
return None, err_put_failed
print err, ".. retry"
- return mkfile(client, key, fsize, extra)
+ mkfile_client = auth.up.Client(uptoken, extra.progresses[-1]["host"])
+ return mkfile(mkfile_client, key, fsize, extra)
# ----------------------------------------------------------
-def resumable_block_put(client, block, index, extra):
+def resumable_block_put(block, index, extra, uptoken):
block_size = len(block)
+ mkblk_client = auth.up.Client(uptoken, conf.UP_HOST)
if extra.progresses[index] is None or "ctx" not in extra.progresses[index]:
end_pos = extra.chunk_size-1
if block_size < extra.chunk_size:
end_pos = block_size-1
chunk = block[: end_pos]
crc32 = gen_crc32(chunk)
chunk = bytearray(chunk)
- extra.progresses[index], err = mkblock(client, block_size, chunk)
+ extra.progresses[index], err = mkblock(mkblk_client, block_size, chunk)
if not extra.progresses[index]["crc32"] == crc32:
return err_unmatched_checksum
if err is not None:
extra.notify_err(index, end_pos + 1, err)
return err
extra.notify(index, end_pos + 1, extra.progresses[index])
+ bput_client = auth.up.Client(uptoken, extra.progresses[index]["host"])
while extra.progresses[index]["offset"] < block_size:
offset = extra.progresses[index]["offset"]
chunk = block[offset: offset+extra.chunk_size-1]
crc32 = gen_crc32(chunk)
chunk = bytearray(chunk)
- extra.progresses[index], err = putblock(client, extra.progresses[index], chunk)
+
+ extra.progresses[index], err = putblock(bput_client, extra.progresses[index], chunk)
if not extra.progresses[index]["crc32"] == crc32:
return err_unmatched_checksum
if err is not None:

0 comments on commit 240ec68

Please sign in to comment.