0

I'm using refile gem for file uploading and I'm uploading files directly to my amazon s3 public bucket. The files are being uploaded just fine to following URL:

https://s3.amazonaws.com/{bucket-name}/store/6309035935359dca1ef549170e7facac9ab3553ad53946cea0bcb8335475

I'm using amazon cloudfront to serve these assets from s3, so the cloudfront url, for the asset given above, is something like this:

https://{distribution-name}.cloudfront.net/store/6309035935359dca1ef549170e7facac9ab3553ad53946cea0bcb8335475

The both urls when accessed directly through browser works fine. To display this asset in my app view file I'm using refile gem following helper function:

attachment_image_tag(@post, :profile_img, :fill, 350, 350)

Now the issue is, this helper method prints a URL something like this:

https://{distribution-name}.cloudfront.net/attachments/5845d0a97dc77a57b5b05742a1eb26d629d7cdaa/store/fill/350/350/6309035935359dca1ef549170e7facac9ab3553ad53946cea0bcb8335475/file

As this URL is different from above cloudfront URL, it is not displaying the image. How do I force attachment_image_tag function to print the correct cloudfront URL?

Faisal Khurshid
  • 1,869
  • 3
  • 21
  • 27

1 Answers1

0

The issue was resolved. The issue was pointed out by another guy on github: https://github.com/refile/refile/issues/500#issuecomment-239784247

It sounds like you may have set up your Cloudfront distribution with your S3 bucket as its origin? Refile, however, does not generate URLs directly to files on S3 (see README section 3. Rack Application). You'll therefore want to set your Cloudfront distribution's origin to be the URL of your application. That way, files will be streamed from your application on the first request, and cached by Cloudfront for future requests.

Faisal Khurshid
  • 1,869
  • 3
  • 21
  • 27