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

yipeiwu_com6年前服务器

复制代码 代码如下:

# _*_ 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()

相关文章

python 从远程服务器下载东西的代码

复制代码 代码如下:# _*_ coding:utf-8 _*_# name gefile.pyimport osimport statimport socketimport param...

利用Python中SocketServer 实现客户端与服务器间非阻塞通信

利用SocketServer模块来实现网络客户端与服务器并发连接非阻塞通信。 首先,先了解下SocketServer模块中可供使用的类: BaseServer:包含服务器的核心功能与混合...

php实现在服务器端调整图片大小的方法

本文实例讲述了php实现在服务器端调整图片大小的方法。分享给大家供大家参考。具体分析如下: 在服务器端完成图片大小的调整,会比在浏览器的处理有很多的好处。 本文介绍了PHP如何在服务器...

Python实现向服务器请求压缩数据及解压缩数据的方法示例

本文实例讲述了Python实现向服务器请求压缩数据及解压缩数据的方法。分享给大家供大家参考,具体如下: 向服务器请求压缩数据格式,并解压缩数据 #!/usr/bin/env pyth...

python Gunicorn服务器使用方法详解

python Gunicorn服务器使用方法详解

1. 简介 Gunicorn(Green Unicorn)是给Unix用的WSGI HTTP 服务器,它与不同的web框架是非常兼容的、易安装、轻、速度快。 2. 示例代码1...