def test_put(self): if is_travis: return src = urllib.urlopen("http://cheneya.qiniudn.com/hello_jpg") ostype = platform.system() if ostype.lower().find("windows") != -1: tmpf = "".join([os.getcwd(), os.tmpnam()]) else: tmpf = os.tmpnam() dst = open(tmpf, 'wb') shutil.copyfileobj(src, dst) src.close() 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) assert err is None, err self.assertEqual(ret["hash"], "FnyTMUqPNRTdk1Wou7oLqDHkBm_p", "hash not match") rs.Client().delete(bucket, key)
def test_put_4m(self): if is_travis: return ostype = platform.system() if ostype.lower().find("windows") != -1: tmpf = "".join([os.getcwd(), os.tmpnam()]) else: tmpf = os.tmpnam() dst = open(tmpf, 'wb') dst.write("abcd" * 1024 * 1024) dst.flush() policy = rs.PutPolicy(bucket) extra = resumable_io.PutExtra(bucket) extra.bucket = bucket extra.params = {"x:foo": "test"} key = "sdk_py_resumable_block_6_%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) assert err is None, err self.assertEqual(ret["hash"], "FnIVmMd_oaUV3MLDM6F9in4RMz2U", "hash not match") rs.Client().delete(bucket, key)
def test_put(self): if is_travis: return src = urllib.urlopen("http://cheneya.qiniudn.com/hello_jpg") ostype = platform.system() if ostype.lower().find("windows") != -1: tmpf = "".join([os.getcwd(), os.tmpnam()]) else: tmpf = os.tmpnam() dst = open(tmpf, 'wb') shutil.copyfileobj(src, dst) src.close() 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) assert err is None, err self.assertEqual( ret["hash"], "FnyTMUqPNRTdk1Wou7oLqDHkBm_p", "hash not match") rs.Client().delete(bucket, key)
def test_put_4m(self): if is_travis: return ostype = platform.system() if ostype.lower().find("windows") != -1: tmpf = "".join([os.getcwd(), os.tmpnam()]) else: tmpf = os.tmpnam() dst = open(tmpf, 'wb') dst.write("abcd" * 1024 * 1024) dst.flush() policy = rs.PutPolicy(bucket) extra = resumable_io.PutExtra(bucket) extra.bucket = bucket extra.params = {"x:foo": "test"} key = "sdk_py_resumable_block_6_%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) assert err is None, err self.assertEqual( ret["hash"], "FnIVmMd_oaUV3MLDM6F9in4RMz2U", "hash not match") rs.Client().delete(bucket, key)
def resumable_upload(param_tuple): uptoken = param_tuple[0] key = param_tuple[1] localfile = param_tuple[2] import qiniu.resumable_io as rio extra = rio.PutExtra(cp.get('qiniu', 'bucket_name')) ret, err = rio.put_file(uptoken, key, localfile, extra) if err is not None: sys.stderr.write('error: %s ' % err) return ret
def test_put(self): policy = rs.PutPolicy(bucket) extra = resumable_io.PutExtra(bucket) extra.bucket = bucket key = "sdk_py_resumable_block_5" localfile = os.path.abspath(os.path.dirname(__file__)) + "/photo_test.jpeg" ret, err = resumable_io.put_file(policy.token(), key, localfile, extra) assert err is None, err self.assertEqual(ret["hash"], "FggslKhqmufiC1VkQvuF2gtvve9P", "hash not match") rs.Client().delete(bucket, key)
def resumable_put_file(): ''' 断点续上传文件 ''' # 尝试删除 qiniu.rs.Client().delete(bucket_name, key) # @gist resumable_put_file localfile = "%s" % __file__ extra = rio.PutExtra(bucket_name) ret, err = rio.put_file(uptoken, key, localfile, extra) if err is not None: sys.stderr.write('error: %s ' % err) return print ret,
def resumable_put_file(): ''' 断点续上传文件 ''' # 尝试删除 rs_client.delete(bucket_name, key) # @gist resumable_put_file localfile = "./%s" % __file__ extra = rio.PutExtra(bucket_name) ret, err = rio.put_file(uptoken, key, localfile, extra) if err is not None: error(err) return print ret,
def test_put(self): src = urllib.urlopen("http://cheneya.qiniudn.com/hello_jpg") dst = tempfile.NamedTemporaryFile() shutil.copyfileobj(src, dst) src.close() policy = rs.PutPolicy(bucket) extra = resumable_io.PutExtra(bucket) extra.bucket = bucket key = "sdk_py_resumable_block_5_%s" % r(9) localfile = dst.name ret, err = resumable_io.put_file(policy.token(), key, localfile, extra) dst.close() assert err is None, err self.assertEqual(ret["hash"], "FnyTMUqPNRTdk1Wou7oLqDHkBm_p", "hash not match") rs.Client().delete(bucket, key)
#!/usr/bin/env python #coding=utf8 import qiniu.conf import qiniu.rsf import qiniu.rs import qiniu.io import sys import qiniu.resumable_io as rio #设置在七牛申请的key qiniu.conf.ACCESS_KEY = "xxxxxxxxxxxx" qiniu.conf.SECRET_KEY = "xxxxxxxxxxxx" #设置七牛的空间名字 bucket_name="xxxx" #设置要同步的文件和在七牛云存储的名字 backup_file=sys.argv[1] backup_name=sys.argv[2] policy = qiniu.rs.PutPolicy(bucket_name) extra = rio.PutExtra(bucket_name) uptoken = policy.token() ret, err = rio.put_file(uptoken, backup_name, backup_file, extra) if err is not None: sys.stderr.write('error: %s ' % err)