Home > Backend Development > Python Tutorial > 本地文件上传到七牛云服务器示例(七牛云存储)

本地文件上传到七牛云服务器示例(七牛云存储)

WBOY
Release: 2016-06-16 08:45:44
Original
1662 people have browsed it

复制代码 代码如下:

# _*_ coding: utf-8 _*_
#---------------------------------------
#   程序:把本地文件上传到七牛云服务器
#   版本:0.1
#   作者:liu jia
#   日期:2014-01-07
#   语言:Python 2.7
#---------------------------------------

import qiniu.conf
import sys
import os
#登录后从#https://portal.qiniu.com/setting/key获取
qiniu.conf.ACCESS_KEY = "xxxxxxxxxxxxxxxxxxx"
qiniu.conf.SECRET_KEY = "xxxxxxxxxxxxxxxxxxx"

import qiniu.io
import qiniu.rs
policy = qiniu.rs.PutPolicy('xxxxx')# 空间名即bucket_name
uptoken = policy.token()

extra = qiniu.io.PutExtra()
extra.mime_type = "image/jpeg"

path = os.getcwd()
print path
picture_path = os.path.join(path, u'豆瓣妹子')
for item in os.listdir(picture_path):
    item = picture_path+'\\'+item
    ret, err = qiniu.io.put_file(uptoken, None, item, extra)
    print item+'---------uploaded'
if err is not None:
    sys.stderr.write('error: %s ' % err)
    exit()

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template