5
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?

More than 3 years have passed since last update.

s3のファイルをダウンロードリンクurl作り

Posted at

S3のファイルをダウンロードurl作る方法

s3にアップしたファイルを、webでダウンロードできるurlの取得方法です。
python使ってます。

s3にあるファイルをwebダウンロードurl取得
image.png

pythonコード

import boto3

s3_client = boto3.client('s3')

BUCKET = 'my-bucket'
OBJECT = 'foo.jpg'

url = s3_client.generate_presigned_url(
    'get_object',
    Params={'Bucket': BUCKET, 'Key': OBJECT},
    ExpiresIn=300)

print(url)
https://xxxxx-voice.s3.amazonaws.com/thumnail.jpg?AWSAccessKeyId=xxxxxxxx&Signature=Zq%2FlTTK6zuD%2BAgtqrjJ2gIHTN9Y%3D&Expires=xxxxx

htmlリンク

<a href="https://xxxx-xxxx.s3.amazonaws.com/thumnail.jpg?AWSAccessKeyId=xxxxx&Signature=Zq%2FlTTK6zuD%2BAgtqrjJ2gIHTN9Y%3D&Expires=1612243885" download>download</a>
5
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
5
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?