Python 3.5
安装 OSS的 Python Sdk
pip install oss2
以下为上传代码(单线程)
import os
import sys
import oss2
#本地路径
basedir='F:\\www\\uutu10'
#目标目录(在Oss中的目录)
ossDir="ossdir"
#id,key填写自己的
ossAuth=oss2.Auth('access_id','access_key')
#bucketName 修改成自己的
ossBucket=oss2.Bucket(ossAuth,'vpc100-oss-cn-shanghai.aliyuncs.com','bucketName')
ee=[1]
ee[0]=0
#最后一次上传到哪个文件,第一次上传请修改 ee[0]=1
ff='uutu10/00/03/84/550.jpg'
def uploadFile(file):
remoteName = ossDir + file.replace(basedir,'').replace('\\','/')
print ('uploading..',file,'remoteName',remoteName)
if (ee[0]==0 and remoteName==ff):
ee[0]=1
if 1==ee[0]:
result=ossBucket.put_object_from_file(remoteName,file)
print('http status: {0}'.format(result.status))
def list(dir):
fs=os.listdir(dir)
for f in fs:
file=dir+"\\"+f;
if os.path.isdir(file):
list(file)
else:
uploadFile(file)
#调用开始
list(basedir)