• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python io.put函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中qiniu.io.put函数的典型用法代码示例。如果您正苦于以下问题:Python put函数的具体用法?Python put怎么用?Python put使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了put函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_put_quote_key

        def test_put_quote_key():
            data = r(100)
            key = 'a\\b\\c"你好' + r(9)
            ret, err = io.put(policy.token(), key, data)
            assert err is None
            assert ret['key'].encode('utf8') == key

            data = r(100)
            key = u'a\\b\\c"你好' + r(9)
            ret, err = io.put(policy.token(), key, data)
            assert err is None
            assert ret['key'] == key
开发者ID:Abner921,项目名称:python-sdk,代码行数:12,代码来源:io_test.py


示例2: test_put_crc_fail

 def test_put_crc_fail(self):
     key = "test_%s" % r(9)
     data = "hello bubby!"
     extra.check_crc = 2
     extra.crc32 = "wrong crc32"
     ret, err = io.put(policy.token(), key, data, extra)
     assert err is not None
开发者ID:13917547121,项目名称:me,代码行数:7,代码来源:io_test.py


示例3: post

    def post(self):
        mimeType = 'application/json'
        if self.request.headers.get('Content-Type', '') == mimeType:
            data = self.request.body
            dataObj = json.loads(data)
            pid = dataObj.get('id', 'default')
            conf.ACCESS_KEY = STORAGE_ACCESS_KEY
            conf.SECRET_KEY = STORAGE_SECRET_KEY
            storagePolicy = rs.PutPolicy(STORAGE_BUCKET)
            storageToken = storagePolicy.token()

            extra = io.PutExtra()
            extra.mime_type = mimeType

            io.put(storageToken, str(pid), data, extra)
        return
开发者ID:dtynn,项目名称:qiniu_demos,代码行数:16,代码来源:app2.py


示例4: test_put_same_crc

 def test_put_same_crc():
     key = "test_%s" % r(9)
     data = "hello bubby!"
     extra.check_crc = 2
     ret, err = io.put(policy.token(), key, data, extra)
     assert err is None
     assert ret['key'] == key
开发者ID:13917547121,项目名称:me,代码行数:7,代码来源:io_test.py


示例5: test_put_same_crc

		def test_put_same_crc():
			key = "test_%s" % r(9)
			params = "op=3"
			data = "hello bubby!"
			extra.check_crc = 2
			ret, err = io.put(policy.token(), key, data, extra)
			assert err is None
开发者ID:icattlecoder,项目名称:python-sdk,代码行数:7,代码来源:io_test.py


示例6: test_put_unicode3

 def test_put_unicode3():
     key = "test_%s" % r(9) + '你好'
     data = key
     key = key.decode('utf8')
     ret, err = io.put(policy.token(), key, data)
     assert err is None
     assert ret[u'key'].endswith(u'你好')
开发者ID:13917547121,项目名称:me,代码行数:7,代码来源:io_test.py


示例7: test_put

		def test_put():
			key = "test_%s" % r(9)
			params = "op=3"
			data = "hello bubby!"
			extra.check_crc = 2
			extra.crc32 = zlib.crc32(data) & 0xFFFFFFFF
			ret, err = io.put(policy.token(), key, data, extra)
			assert err is None
开发者ID:icattlecoder,项目名称:python-sdk,代码行数:8,代码来源:io_test.py


示例8: writeQnData

	def writeQnData(self, key, mf):
		while True:
			ret, err = io.put(uptoken, key, mf, extra)
			if err is not None:
				logger.error(err)
			else:
				logger.info(ret)
				break
开发者ID:anzhj,项目名称:aqtools,代码行数:8,代码来源:uptile2qn.py


示例9: save_file_qiniu

def save_file_qiniu(binary, filename, mime="application/octet-stream"):
    policy = rs.PutPolicy(QiniuConf.BUCKET_NAME)
    uptoken = policy.token()
    extra = io.PutExtra()
    extra.mime_type = mime
    res, err = io.put(uptoken, filename, binary, extra)
    if err is not None:
        return 'none'
    url = rs.make_base_url(QiniuConf.BUCKET_DOMAIN, filename)
    return url
开发者ID:wbbim,项目名称:getlink,代码行数:10,代码来源:common.py


示例10: _put_file

    def _put_file(self, name, content):

        if self.encrypt_func:
            content = self.encrypt_func(content)

        policy = rs.PutPolicy(self.bucket)
        uptoken = policy.token()
        ret, err = io.put(uptoken, name, content)
        if err is not None:
            raise IOError("QiniuStorageError: %s", err)
开发者ID:jeffkit,项目名称:qiniu-storage,代码行数:10,代码来源:storage.py


示例11: process_item

    def process_item(self, item, spider):
        # 获得上传权限
        qiniu.conf.ACCESS_KEY = "QBsaz_MsErywKS2kkQpwJlIIvBYmryNuPzoGvHJF"
        qiniu.conf.SECRET_KEY = "OTi4GrXf8CQQ0ZLit6Wgy3P8MxFIueqMOwBJhBti"

        # 配置上传策略。
        # 其中lvxingpai是上传空间的名称(或者成为bucket名称)
        policy = qiniu.rs.PutPolicy('lvxingpai-img-store')
        # 取得上传token
        uptoken = policy.token()

        # 上传的额外选项
        extra = io.PutExtra()
        # 文件自动校验crc
        extra.check_crc = 1

        upload_stream = False

        # 将相应的数据存入mongo中
        client = pymongo.MongoClient('zephyre.me', 27017)
        db = client.imagestore

        # 检查是否已经入mongo库
        if db.Hotel.find_one({'url_hash': str(item['hash_value'])}) is None:
            # 先生成本地文件
            localfile = str(time.time()) + str(random.random())

            with open(localfile, 'wb') as f:
                f.write(item['pic'])
            # 上传
            if upload_stream:
                # 上传流
                with open(localfile, 'rb') as f:
                    body = f.read()
                ret, err = io.put(uptoken, str(item['key']), body, extra)
            else:
                # 上传本地文件
                ret, err = io.put_file(uptoken, str(item['key']), localfile, extra)

            if err is not None:
                sys.stderr.write('error: %s ' % err)
                return

            # 计算文件大小,进入mongo
            file_size = int(getsize(localfile))
            db.Hotel.save({'url': item['url'], 'key': item['key'],
                           'url_hash': item['hash_value'], 'ret_hash': ret['hash'], 'size': file_size})
            # 增加索引
            db.Hotel.create_index('url_hash')


            # 删除上传成功的文件
            os.remove(localfile)
        return item
开发者ID:Lvxingpai,项目名称:Andaman,代码行数:54,代码来源:pipelines.py


示例12: post

 def post(self):
     files = self.request.files.get('upload_file')
     if not files:
         self.write('no file')
         return
     data = files[0].get('body')
     key = 'upload_app'
     putPolicy = qRs.PutPolicy(scope='%s:%s' % (BUCKET, key))
     uptoken = putPolicy.token()
     print 'up up uploading'
     ret, err = qIo.put(uptoken, key, data)
     if err:
         self.write(err)
     else:
         self.write('http://%s/%s' % (QINIU_DOMAIN, key))
     return
开发者ID:dtynn,项目名称:qiniu-video-demo,代码行数:16,代码来源:upload_app.py


示例13: test_put_no_length

		def test_put_no_length():
			class test_reader(object):
				def __init__(self):
					self.data = 'abc'
					self.pos = 0
				def read(self, n=None):
					if n is None or n < 0:
						newpos = len(self.data)
					else:
						newpos = min(self.pos+n, len(self.data))
					r = self.data[self.pos: newpos]
					self.pos = newpos
					return r
			key = "test_%s" % r(9)
			data = test_reader()

			extra.check_crc = 2
			extra.crc32 = binascii.crc32('abc') & 0xFFFFFFFF
			ret, err = io.put(policy.token(), key, data, extra)
			assert err is None
			assert ret['key'] == key
开发者ID:jack-zh,项目名称:zorder,代码行数:21,代码来源:io_test.py


示例14: save_file_qiniu

    def save_file_qiniu(binary, filename, mime="application/octet-stream"):

        today = datetime.now().strftime("%Y/%m/%d/")
        filename = today + filename

        policy = rs.PutPolicy(QINIU_SETTINGS.BUCKET_NAME)
        uptoken = policy.token()

        extra = io.PutExtra()
        extra.mime_type = mime

        res, err = io.put(uptoken, filename, binary, extra)
        if err is not None:
            raise Exception("Qiniu save file [%s] error: %s res: %s" % (filename, err, res))

        url = rs.make_base_url(QINIU_SETTINGS.BUCKET_DOMAIN, filename)

        iv = fop.ImageView()
        iv.mode = 2
        iv.width = THUMB_SIZE[0]
        url_thumb = iv.make_request(url)

        return url, url_thumb
开发者ID:13917547121,项目名称:me,代码行数:23,代码来源:common.py


示例15: test_put_unicode1

 def test_put_unicode1():
     key = "test_%s" % r(9) + '你好'
     data = key
     ret, err = io.put(policy.token(), key, data, extra)
     assert err is None
     assert ret[u'key'].endswith(u'你好')
开发者ID:13917547121,项目名称:me,代码行数:6,代码来源:io_test.py


示例16: test_put_no_key

 def test_put_no_key():
     data = r(100)
     extra.check_crc = 0
     ret, err = io.put(policy.token(), key=None, data=data, extra=extra)
     assert err is None
     assert ret['hash'] == ret['key']
开发者ID:13917547121,项目名称:me,代码行数:6,代码来源:io_test.py


示例17: test_put_fail_reqid

 def test_put_fail_reqid(self):
     key = "test_%s" % r(9)
     data = "hello bubby!"
     ret, err = io.put("", key, data, extra)
     assert "reqid" in err
开发者ID:13917547121,项目名称:me,代码行数:5,代码来源:io_test.py


示例18: test_put_urlopen

 def test_put_urlopen():
     key = "test_%s" % r(9)
     data = urllib.urlopen('http://cheneya.qiniudn.com/hello_jpg')
     ret, err = io.put(policy.token(), key, data)
     assert err is None
     assert ret['key'] == key
开发者ID:13917547121,项目名称:me,代码行数:6,代码来源:io_test.py


示例19: test_put_StringIO

 def test_put_StringIO():
     key = "test_%s" % r(9)
     data = cStringIO.StringIO('hello buddy!')
     ret, err = io.put(policy.token(), key, data)
     assert err is None
     assert ret['key'] == key
开发者ID:13917547121,项目名称:me,代码行数:6,代码来源:io_test.py


示例20: reload

reload(sys)
sys.setdefaultencoding('utf-8')
sys.path.insert(0, '../')

from qiniu import conf as qConf, rs as qRs, io as qIo

ACCESS_KEY = ''
SECRET_KEY = ''
BUCKET = ''
QINIU_DOMAIN = ''

qConf.ACCESS_KEY = ACCESS_KEY
qConf.SECRET_KEY = SECRET_KEY

if __name__ == '__main__':
    putPolicy = qRs.PutPolicy(scope=BUCKET)
    uptoken = putPolicy.token()

    filePath = '../files/test.jpg'

    key = 'upload_put.jpg'

    f = open(filePath, 'rb')
    data = f.read()

    #上传结果
    ret, err = qIo.put(uptoken, key, data)
    print ret
    print err
    if err is None:
        print 'http://%s/%s' % (QINIU_DOMAIN, key)
开发者ID:dtynn,项目名称:qiniu-video-demo,代码行数:31,代码来源:upload_put.py



注:本文中的qiniu.io.put函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python qiskit.QuantumCircuit类代码示例发布时间:2022-05-26
下一篇:
Python config.get_default函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap