1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?