Skip to content

resumableio: use mkfile #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions qiniu/resumable_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def gen_crc32(data):
return binascii.crc32(data) & 0xffffffff

class PutExtra(object):
callback_params = None # 当 uptoken 指定了 CallbackUrl,则 CallbackParams 必须非空
bucket = None # 当前是必选项,但未来会去掉
custom_meta = None # 可选。用户自定义 Meta,不能超过 256 字节
params = None # 自定义用户变量, key需要x: 开头
mimetype = None # 可选。在 uptoken 没有指定 DetectMime 时,用户客户端可自己指定 MimeType
chunk_size = None # 可选。每次上传的Chunk大小
try_times = None # 可选。尝试次数
Expand Down Expand Up @@ -153,17 +151,17 @@ def putblock(client, block_ret, chunk):
return client.call_with(url, chunk, content_type, len(chunk))

def mkfile(client, key, fsize, extra):
encoded_entry = urlsafe_b64encode("%s:%s" % (extra.bucket, key))
url = ["http://%s/rs-mkfile/%s/fsize/%s" % (conf.UP_HOST, encoded_entry, fsize)]
url = ["http://%s/mkfile/%s" % (conf.UP_HOST, fsize)]

if extra.mimetype:
url.append("mimeType/%s" % urlsafe_b64encode(extra.mimetype))

if extra.custom_meta:
url.append("meta/%s" % urlsafe_b64encode(extra.custom_meta))
if key is not None:
url.append("key/%s" % urlsafe_b64encode(key))

if extra.callback_params:
url.append("params/%s" % urlsafe_b64encode(extra.callback_params))
if extra.params:
for k, v in extra.params.iteritems():
url.append("%s/%s" % (k, urlsafe_b64encode(v)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处k直接拼接入url,如果用户提供的自定义变量名包含url-unsafe的字符会发生什么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

自定义变量名的命名用户可控,可以规避
服务端也没有进行相应的encode措施


url = "/".join(url)
body = ",".join([i["ctx"] for i in extra.progresses])
Expand Down
2 changes: 2 additions & 0 deletions qiniu/test/resumable_io_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ def test_put(self):
policy = rs.PutPolicy(bucket)
extra = resumable_io.PutExtra(bucket)
extra.bucket = bucket
extra.params = {"x:foo": "test"}
key = "sdk_py_resumable_block_5_%s" % r(9)
localfile = dst.name
ret, err = resumable_io.put_file(policy.token(), key, localfile, extra)
assert ret.get("x:foo") == "test", "return data not contains 'x:foo'"
dst.close()
os.remove(tmpf)

Expand Down