Created
September 25, 2014 13:59
-
-
Save omengye/fc9852fe5c202a0f9fd1 to your computer and use it in GitHub Desktop.
qiniu python sdk 上传图片
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| import os | |
| import sys | |
| import qiniu.conf | |
| import qiniu.io | |
| import qiniu.rs | |
| import qiniu.fop | |
| qiniu.conf.ACCESS_KEY = "***" | |
| qiniu.conf.SECRET_KEY = "***" | |
| tokenObj = qiniu.rs.PutPolicy('diaobaopic') | |
| extra = qiniu.io.PutExtra() | |
| extra.mime_type = "image/jpeg" | |
| path = os.getcwd() | |
| pic_path = os.path.join(path,'pic') | |
| pics = os.listdir(pic_path) | |
| for pic_name in pics: | |
| pic = pic_path + '\\' + pic_name | |
| uploadtoken = tokenObj.token() | |
| ret, err = qiniu.io.put_file(uploadtoken, pic_name.split('.')[0], pic, extra) | |
| print pic_name + ' uploaded!' | |
| if err is not None: | |
| sys.stderr.write('error: %s ' % err) | |
| print "error" | |
| exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment