I’m new to aws so this might be trivial but bear with me please.
So I want to upload images and other types of files to s3 bucket from the browser ,as i understand i need to get a pre signed url using my credentials from the server side and send it to the browser so the client can upload the file to the bucket, the bucket will be public for to read .
So my question is how to get the file url so any one can access it ?
I’ve read that i should construct it using the file key and the bucket name…
(http://s3-REGION-.amazonaws.com/BUCKET-NAME/KEY) …
Is there other ways to do it ?
need more details. i’d download the file and use the aws cli to sync my bucket with my downloads folder.
if i was making a browser plug in i would have made an api i can use that invokes a lambda and returns the presigned url that i use to preform the upload.
If you want it to look nicer, you’ll need some additional layer in front of your bucket, for example a Cloudfront distribution with a linked domain name.
With CF you won’t have to make your bucket public btw, as files will be served from the CF edge locations and S3 bucket will be acting as an origin and will be only accessible by the CF.
You can point a domain name to the bucket using a CNAME, which allows you to access the bucket like “mybucket.mywebsite.com/file.txt” instead:
https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#VirtualHostingCustomURLs
However to get HTTPS support you must put CloudFront in front of the bucket:
https://aws.amazon.com/premiumsupport/knowledge-center/cloudfront-https-requests-s3/
You may want to check out AWS’s Serverless Image Handler. It handles all the mechanics of serving files by setting up an API Gateway endpoint, caching with Cloudfront, etc. The docs do a pretty good job of describing how to set it all up.
For the front-end, you’ll want to use the AWS SDK for S3. Amplify also has a decent-enough interface for uploading files to S3 that can get you up and running quickly.
Hi
how will you combine the cloudfront and the generated presigned url of the s3?
Cloudfront has its own presigned URL mechanism.
You can do basically anything with a lambda function hooked up to the “origin request” event on the CloudFront distribution. More specific suggestions would require more specific feature description.
thanks!
thanks!
It’s very easy to do that select the bucket , unblock all the permission and save
Then select the or file or image in the bucket and make the public and then u r good to go with ur image URL which will be objecturl and can be accessed by anyone.