Skip to content

Instantly share code, notes, and snippets.

@omengye
Created September 25, 2014 13:59
Show Gist options
  • Select an option

  • Save omengye/fc9852fe5c202a0f9fd1 to your computer and use it in GitHub Desktop.

Select an option

Save omengye/fc9852fe5c202a0f9fd1 to your computer and use it in GitHub Desktop.
qiniu python sdk 上传图片
# -*- 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