Example #1
0
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,
Example #2
0
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,
Example #3
0
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('')
Example #4
0
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']
Example #5
0
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']
Example #6
0
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,
Example #7
0
    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)
Example #8
0
    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)