I am saving a key to a bucket with:
key = bucket.new_key(fileName)
key.set_contents_from_string(base64.b64decode(data))
key.set_metadata('Content-Type', 'image/jpeg')
key.set_acl('public-read')
After the save is successful, how can I access the URL of the newly created file?
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.
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.
To generate a presigned URL using the AWS Management ConsoleIn the Buckets list, choose the name of the bucket that contains the object that you want a presigned URL for. In the Objects list, select the object that you want to create a presigned URL for. On the Actions menu, choose Share with a presigned URL.
http://s3tools.org/s3cmd works pretty well and support the s3:// form of the URL structure you want. It does the business on Linux and Windows. If you need a native API to call from within a python program then http://code.google.com/p/boto/ is a better choice.
If the key is publicly readable (as shown above) you can use Key.generate_url
:
url = key.generate_url(expires_in=0, query_auth=False)
If the key is private and you want to generate an expiring URL to share the content with someone who does not have direct access you could do:
url = key.generate_url(expires_in=300)
where expires
is the number of seconds before the URL expires. These will produce HTTPS url's. If you prefer an HTTP url, use this:
url = key.generate_url(expires_in=0, query_auth=False, force_http=True)
For Boto3, you need to do it the following way...
import boto3
s3 = boto3.client('s3')
url = '{}/{}/{}'.format(s3.meta.endpoint_url, bucket, key)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With