I followed the tutorial at refile/refile and try to use `refile-s3 to upload my photos to S3. However, it is still uploading to my localhost.. I wonder why??
Code in Github: https://github.com/chrisyeung1121/refile-example
Am I missing anything?
I followed the tutorial at refile/refile and try to use `refile-s3 to upload my photos to S3. However, it is still uploading to my localhost.. I wonder why??
Code in Github: https://github.com/chrisyeung1121/refile-example
Am I missing anything?
I ran the example app and everything is done correctly, the file is uploaded to S3. You can see this when viewing your s3 bucket there should be a /store
folder with a file inside thats looks similar to this: 8d005532259e4abc0.....
It will correspond with the id saved in your database. In your case the id is stored as profile_image_id in your User model.
It may be confusing that the result of attachment_url
is returning <img src="/attachments/store/fill/300/300/8d005532259e4abc0...../profile_image.jpg" alt="Profile image">
making it seem like it is still being uploaded to the localhost.
What is happening is that refile downloads the file from amazon s3, modifies it to 300x300 on the fly and sends it to the browser. However this shouldn't be done every time the page is loaded since it would waste a lot of processing power. This is where a CDN is needed, and refile is designed to use one. This way the processed imaged gets cached and everything is much faster.
in the refile.rb
config file:
Refile.cdn_host = "https://your-dist-url.cloudfront.net"
or in my case I restricted it to production:
if Rails.env.production?
Refile.cdn_host = "https://your-dist-url.cloudfront.net"
end
note that .cdn_host should be .host if using a version below 0.6.0
Now this should return something like <img src="https://your-dist-url.cloudfrond.net/attachments/store/fill/300/300/8d005532259e4abc0...../profile_image.jpg" alt="Profile image">
You can read more about it in the official documentation.