def rapid_upload(cookie, tokens, source_path, path, upload_mode): '''快速上传''' ondup = const.UPLOAD_ONDUP[upload_mode] content_length = os.path.getsize(source_path) assert content_length > RAPIDUPLOAD_THRESHOLD, 'file size is not satisfied!' dir_name, file_name = os.path.split(path) content_md5 = hasher.md5(source_path) slice_md5 = hasher.md5(source_path, 0, RAPIDUPLOAD_THRESHOLD) url = ''.join([ const.PCS_URL_C, 'file?method=rapidupload&app_id=250528', '&ondup=', ondup, '&dir=', encoder.encode_uri_component(dir_name), '&filename=', encoder.encode_uri_component(file_name), '&content-length=', str(content_length), '&content-md5=', content_md5, '&slice-md5=', slice_md5, '&path=', encoder.encode_uri_component(path), '&', cookie.sub_output('BDUSS'), '&bdstoken=', tokens['bdstoken'], ]) req = net.urlopen(url, headers={'Cookie': cookie.header_output()}) if req: return json.loads(req.data.decode()) else: return None
def rapid_upload(cookie, tokens, source_path, path, upload_mode): '''快速上传''' ondup = const.UPLOAD_ONDUP[upload_mode] if not ondup: ondup = 'newcopy' content_length = os.path.getsize(source_path) assert content_length > RAPIDUPLOAD_THRESHOLD, 'file size is not satisfied!' dir_name, file_name = os.path.split(path) content_md5 = hasher.md5(source_path) slice_md5 = hasher.md5(source_path, 0, RAPIDUPLOAD_THRESHOLD) url = ''.join([ const.PCS_URL_C, 'file?method=rapidupload&app_id=250528', '&ondup=newcopy', '&dir=', encoder.encode_uri_component(dir_name), '&filename=', encoder.encode_uri_component(file_name), '&content-length=', str(content_length), '&content-md5=', content_md5, '&slice-md5=', slice_md5, '&path=', encoder.encode_uri_component(path), '&', cookie.sub_output('BDUSS'), '&bdstoken=', tokens['bdstoken'], ]) req = net.urlopen(url, headers={'Cookie': cookie.header_output()}) if req: return json.loads(req.data.decode()) else: return None