问题
I have just integrated AWS with my rails/heroku app and I am using paperclip. I am able to upload files (photo's) and see them in AWS, however they are not showing up in the view. I am not getting any errors, and have not found a working solution in other posts.
It seems I am able to view the image in a browser, and that permissions are set to public:
I suspect that I may have my region wrong, in the url of my aws dashboard the region says region=us-west-2 yet googling and reading through other forums and posts on SO leads me to believe that if I am in the US my region should be set to us-east-1 - currently I have it set to the latter. Not sure if this is the problem.
Here is a link to the image on AWS:https://s3.amazonaws.com/giving-tree-images/avatars/1/medium/02108_navajoland_1440x900.jpg
here is the code pertaining to aws/paperclip in my model:
:storage => :s3,
# :s3_host_name => "s3-us-east-1.amazonaws.com",
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
},
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:default_url => "default_img.png"
and I am displaying in the view like this:
<%= image_tag @user.avatar.url(:medium) %>
I would love it if someone could point me in the right direction... Any additional info needed, please let me know!
回答1:
I also faced the same issue, so this is how I solved it:
- Create a new initializer file i.e. config/initializers/paperclip.rb
- Add following in this file
Paperclip::Attachment.default_options[:url] = ':s3_domain_url' Paperclip::Attachment.default_options[:s3_host_name] = 's3-us-west-2.amazonaws.com'
To get details about your region, go to aws
Amazon Web Service - Check your host name
Note : Replace s3-us-west-2.amazonaws.com with your own host name
Reference : https://devcenter.heroku.com/articles/paperclip-s3
回答2:
Have you enable the read permission to everyone? It gave me access-denied error when accessed to the link.
来源:https://stackoverflow.com/questions/38778934/images-uploaded-to-aws-but-cant-be-viewed-in-the-view