Python 3 Boto 3, AWS S3: Get object URL

后端 未结 4 2114
Happy的楠姐
Happy的楠姐 2020-12-19 00:38

I need to retrieve an public object URL directly after uploading a file, this to be able to store it in a database. This is my upload code:

   s3 = boto3.res         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 01:11

    Since 2010 you can use a virtual-hosted style S3 url, i.e. no need to mess with region specific urls:

    url = f'https://{bucket}.s3.amazonaws.com/{key}'
    

    Moreover, support for the path-style model (region specific urls) continues for buckets created on or before September 30, 2020. Buckets created after that date must be referenced using the virtual-hosted model.

    See also this blog post.

提交回复
热议问题