Carrierwave s3 403 (Forbidden) error
Asked Answered
Q

0

2

I'm trying to get carrierwave to work with Amazon S3 (in my Rails 4 app), I use fog gem to upload the images to s3.

I'm currently successfully able to upload the files to my bucket. But I cannot get the images back. server is giving 403 (Forbidden) error

However if I check the image, it's there uploaded in S3. My image path would be something like

https://<bucket name>.s3.amazonaws.com/uploads/image/picture/8/card_34676_l.jpg&Signature=<signature>&Expires=<expires>

Following is my carrierwave config

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',
    :aws_access_key_id      => '<key>',
    :aws_secret_access_key  => '<access key>',
  }
  config.fog_directory  = '<bucket name>' 
  config.fog_public     = false  
  config.fog_attributes = {'Cache-Control'=>"max-age=#{365.day.to_i}"} # optional, defaults to {}
end

and I have setup the default grantee permission to everyone with

  • list
  • upload/delete
  • view permissions

and have a default CORS Configuration setup

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>Authorization</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

What could be missing?

Quadrate answered 13/11, 2014 at 13:40 Comment(3)
Hey, sorry to hear you are having trouble. Just a couple questions to clarify. In what way are you trying to access them? ie via the url or by using the internal carrierwave functionality? If it is the url, how are you generating it?Trophy
Hey @geemus, thanks for the comment, actually it turns out to be a mistake from my side ;) My bucket didnt have a bucket policy, adding a policy with read access for the content fixed the issue. thanks again and keep up the good work on fog :)Quadrate
Glad to hear you found the fix and thanks for taking time to update with the details!Trophy

© 2022 - 2024 — McMap. All rights reserved.