赞
踩
在使用python的boto3库进行s3的操作时,发现官方文档介绍的并不好用,并且搜了很多文章也不好用,那记录一下自己的经验,以备需要
import boto3
from typing import Any, Dict
class S3():
def __init__(self, config: Dict[str,Any]):
self.config = config
@property
def s3_client(self):
return boto3.resource(
's3',
endpoint_url="Endpoint",
aws_access_key_id = "AK",
aws_secret_access_key = "SK",
)
def S3Download(self) -> None:
objs = self.s3_client.Bucket("bucket_name").objects.all()
for obj in objs:
self.s3_client.Bucket("bucket_name").download_file(obj.key,"本地文件名称")
def S3list(self):
objs = self.s3_client.Bucket("bucket_name").objects.all()
for obj in objs:
print(obj)
def Upload(self) -> None:
self.s3_client.Bucket("bucket_name").upload_file("本地文件名称","bucket上文件名称")
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。