def resumable_put(): ''' 断点续上传 ''' # 尝试删除 rs_client = qiniu.rs.Rs() rs_client.delete(bucket_name, key) # @gist resumable_put class ResumableUpload(object): position = 0 def __init__(self, string_data): self.data = string_data def read(self, length): data = self.data[self.position: self.position+length] self.position += length return data a = "resumable upload string" extra = rio.PutExtra(bucket_name) extra.mime_type = "text/plain" ret, err = rio.put(uptoken, key, ResumableUpload(a), len(a), extra) if err is not None: error(err) return print ret,
def resumable_put(): ''' 断点续上传 ''' # 尝试删除 rs_client = qiniu.rs.Rs() rs_client.delete(bucket_name, key) # @gist resumable_put class ResumableUpload(object): position = 0 def __init__(self, string_data): self.data = string_data def read(self, length): data = self.data[self.position:self.position + length] self.position += length return data a = "resumable upload string" extra = rio.PutExtra(bucket_name) extra.mime_type = "text/plain" ret, err = rio.put(uptoken, key, ResumableUpload(a), len(a), extra) if err is not None: error(err) return print ret,
def upload(key, data): uptoken = policy.token() extra = rio.PutExtra('cntrains') try: ret, err = rio.put(uptoken, key, StringIO.StringIO(data), len(data), extra) if err is not None: logger.warn('upload error: %s ' % err) except: logger.exception('')
def upload_by_rawdata(rawdata, length): policy = qiniu_rs.PutPolicy(qiniu_bucket) uptoken = policy.token() extra = rio.PutExtra(qiniu_bucket) ret, err = rio.put(uptoken, None, rawdata, length, extra) if err is not None: log.error('rio put raw file return ret:%s, err:%s' % (str(ret), err)) return None else: log.info('rio put raw file return ret:%s, err:%s' % (str(ret), err)) return ret['key']
def upload_by_rawdata(rawdata, length): policy = qiniu_rs.PutPolicy(qiniu_bucket) uptoken = policy.token() extra = rio.PutExtra(qiniu_bucket) ret, err = rio.put(uptoken, None, rawdata, length, extra) if err is not None: log.error('rio put raw file return ret:%s, err:%s' %(str(ret), err)) return None else: log.info('rio put raw file return ret:%s, err:%s' %(str(ret), err)) return ret['key']
def resumable_put(): ''' 断点续上传 ''' # 尝试删除 qiniu.rs.Client().delete(bucket_name, key) # @gist resumable_put a = "resumable upload string" extra = rio.PutExtra(bucket_name) extra.mime_type = "text/plain" ret, err = rio.put(uptoken, key, StringIO.StringIO(a), len(a), extra) if err is not None: sys.stderr.write('error: %s ' % err) return print ret,
def test_put_0(self): if is_travis: return f = StringIO.StringIO('') policy = rs.PutPolicy(bucket) extra = resumable_io.PutExtra(bucket) extra.bucket = bucket extra.params = {"x:foo": "test"} key = "sdk_py_resumable_block_7_%s" % r(9) ret, err = resumable_io.put(policy.token(), key, f, 0, extra) assert err is None, err assert ret.get("x:foo") == "test", "return data not contains 'x:foo'" self.assertEqual(ret["hash"], "Fg==", "hash not match") rs.Client().delete(bucket, key)
def test_put_0(self): if is_travis: return f = StringIO.StringIO('') policy = rs.PutPolicy(bucket) extra = resumable_io.PutExtra(bucket) extra.bucket = bucket extra.params = {"x:foo": "test"} key = "sdk_py_resumable_block_7_%s" % r(9) ret, err = resumable_io.put(policy.token(), key, f, 0, extra) assert err is None, err assert ret.get("x:foo") == "test", "return data not contains 'x:foo'" self.assertEqual( ret["hash"], "Fg==", "hash not match") rs.Client().delete(bucket, key)