Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Amazon S3 files: get full url of file uploaded in json response via postman

General • Asked by LOUY ABDALRIDA

Hello I have api rails app that I can upload files via carrierwave to my s3 bucket and I got back checksum and id in the response now I am trying to add the url of the file uploaded with the json response ?
now I have this :
"id": 5,
"checksum": "4B1E2AAFE1BC3B7D79AB39F2834FEF81826054610DB951AA60D3965F609BB6",
"file_refrence": null

What is the name of the carrierwave string column you use for this file?

If it file for example than the url is simply file_url as a result of the fact that you are using carrierwave. Or if you wanted a specific version, you could use file.thumb.url.

Thank you Tomas Bush
That will return the file path not the uploaded url file!
I am looking for the AWS s3 url

So I may be making inacurate assumptions, but I think you want to receive a cloudfront url instead of an s3 url. Cloudfront is a CDN distribution that you attach to an s3 bucket. If so, I layout the process below. Once done, restart your app and file_url should return a cloudfront url that is the image in the s3 bucket.

Reason you would want cloudfront url instead of s3 url
s3 is intentionally not overly quick retrieving/serving assets -- you will want to create a cloudfront distribution and attach it to the s3. I believe its a pretty straight forward process, just essentially choose your s3 bucket in the cloudfront creation process -- cloudfront will keep itself in sync with your bucket so no worries there. In that scenario, s3 accepts and stores images from your rails app, while cloudfront is the CDN for your s3 bucket -- so all images will have a cloudfront base url.

Than add one more line to your config/initializers/carrierwave.rb, it will look like this:
config.asset_host = ''

Example carrierwave.rb

CarrierWave.configure do |config|
  config.fog_credentials = {
    ...your credentials
  config.fog_directory  = 'YOUR-BUCKET'
  config.asset_host = ''
  config.fog_attributes = {'Cache-Control'=>'max-age=315576000'}  # optional, defaults to {}

Thank you Tomas Bush
sorry been busy thank you so much for you help ;D

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.