LoginSignup
1
1

【Python】S3の署名付きURL発行でダウンロードするファイルのファイル名を指定する方法

Last updated at Posted at 2024-04-16

ドキュメント にもやり方が書いていないので残しておきます。

Paramsパラメータに 'ResponseContentDisposition': f"attachment; filename = ファイル名" を設定します。
※ ファイル名をURLエンコードするのを忘れないように注意。

from urllib.parse import quote
filename = quote("サンプルファイルだよ.txt")  # ファイル名をURLエンコード

presigned_url = s3_client.generate_presigned_url(
    ClientMethod = "get_object",
    Params={
        "Bucket":get_env().output_app_bucket,
        "Key":os.path.join(job.dst_file_path, translated_file_path),
        'ResponseContentDisposition': f"attachment; filename = {filename}",
    },
    ExpiresIn="3600",
    HttpMethod="GET"
)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1