shimoda.m@nds-tyo.co.jp 65acc3ce09 style: format適用
2023-05-12 13:39:14 +09:00

33 lines
1.0 KiB
Python

from urllib.parse import quote
import boto3
from src.aws.aws_api_client import AWSAPIClient
class S3Client(AWSAPIClient):
__s3_client = boto3.client('s3')
def upload_file(self, local_file_path: str, bucket_name: str, file_key: str):
self.__s3_client.upload_file(
local_file_path,
Bucket=bucket_name,
Key=file_key
)
def generate_presigned_url(self, bucket_name: str, file_key: str, download_filename: str = ''):
# presigned_urlを生成
presigned_url = self.__s3_client.generate_presigned_url(
'get_object',
Params={
'Bucket': bucket_name,
'Key': file_key,
# 別ファイル名に変更するための仕掛け。Unicode文字はquoteでエスケープが必要
'ResponseContentDisposition': f'attachment; filename="{quote(download_filename)}"'
},
# 有効期限20分
ExpiresIn=1200
)
return presigned_url