python下载oss指定文件夹下的信息到指定路径

1、运行环境
windows 


2、test.py代码:
#!/usr/bin/env python3
import oss2
import os
from itertools import islice
from pathlib import Path
 
# 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
auth = oss2.Auth('yourAccessKeyId', 'yourAccessKeySecret')


 
# yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。

bucket = oss2.Bucket(auth, endpoint, 'examplebucket')     
download_local_save_prefix = "F:/test/"#windows路径


# oss2.ObjectIteratorr用于遍历文件。
num = 0
for b in islice(oss2.ObjectIterator(bucket,prefix="test/"), 500000):#指定下载bucket地址, "test/"下的文件
        print("downloadfile-->",b.key)
        bucket.get_object_to_file(b.key,download_local_save_prefix + b.key)
print(num)

猜你喜欢

转载自blog.csdn.net/Penrosee/article/details/120287198