Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting file url after upload amazon s3 python, boto3

I'm just a new with boto3 and i can not understand how i can get URL link for file that i have just uploaded to s3 amazon.

Please clarify.

Thank you

import boto3

s3 = boto3.resource('s3')

data = open ('file.xlsx', 'rb')
s3.Bucket ('dimxxx1').put_object (Key='file.xlsx', Body=data)
like image 501
J_log Avatar asked Nov 04 '18 23:11

J_log


People also ask

How do I get my S3 upload URL?

You can get the resource URL either by calling getResourceUrl or getUrl . AmazonS3Client s3Client = (AmazonS3Client)AmazonS3ClientBuilder. defaultClient(); s3Client. putObject(new PutObjectRequest("your-bucket", "some-path/some-key.

How do I find my S3 bucket URL?

Get an S3 Object's URL #Navigate to the AWS S3 console and click on your bucket's name. Use the search input to find the object if necessary. Click on the checkbox next to the object's name. Click on the Copy URL button.

What is Presign URL?

A presigned URL gives you access to the object identified in the URL, provided that the creator of the presigned URL has permissions to access that object.


1 Answers

First, the better way to upload would be:

import boto3
s3 = boto3.resource('s3')
s3.Bucket('dimxxx1').upload_file('/tmp/file.xlsx', 'file.xlsx')

To obtain the URL, you can construct it from the basic elements:

http://s3-REGION-.amazonaws.com/BUCKET-NAME/KEY

For example:

http://s3-ap-southeast-2.amazonaws.com/dimxxx1/file.xlsx
like image 127
John Rotenstein Avatar answered Oct 01 '22 16:10

John Rotenstein