七牛文件上传-python
1 #!/usr/bin/env python 2 # -*- coding: utf-8 -*- 3 4 import sys 5 import os 6 7 from sevencow import CowException 8 from sevencow import Cow 9 10 11 12 ACCESS_KEY = 'YOUR_ACCESS_KEY' 13 SECRET_KEY = 'YOUR_SECRET_KEY' 14 BUCKET_NAME = 'YOUR_BUCKET_NAME' 15 16 cow = Cow(ACCESS_KEY, SECRET_KEY) 17 b = cow.get_bucket(BUCKET_NAME) 18 19 20 if __name__ == '__main__': 21 #获得输入 22 file_path = sys.argv[1] 23 #判断路径是否存在,是否是文件 24 if os.path.exists(file_path) and os.path.isfile(file_path): 25 try: 26 b.put(file_path) 27 except CowException as e: 28 print e.url,e.status_code,e.reason,e.content
看代码就知道,需要先安装sevencow,上传文件很简单,以文件路径为参数即可。