python sdk上传文件到阿里云oss

!/usr/bin/python

import oss2
import sys

print 'input file:', sys.argv[1]
destFileName = sys.argv[1]
auth = oss2.Auth('$AccessKeyID', '$AccessKeySecret')
bucket = oss2.Bucket(auth, '区名', '桶名')
result = bucket.put_object_from_file(sys.argv[1], destFileName)
if result.status == 200:
print 'upload success'
else:
print 'upload fail,error code', result.status

使用


python main.py 文件名

其它

  1. 需要安装oss2库,用pip安装即可

    sudo pip install oss2
  2. 一般用阿里云服务器作为中转

你可能感兴趣的:(python sdk上传文件到阿里云oss)