s3_file_field with AWS_REGION 'us-west-2'

Maybe you had faced this error using s3_file_field:

The authorization header is malformed; the region 'us-east-1' is wrong; expecting 'us-west-2'

First of all, if you can get rid off, please do it s3_file_field get retired.

Please use shrine instead ❤️

But if you cannot do that and you are using Heroku and Fog.

Don't follow the path trying to add AWS_REGION to:

S3FileField.config do |c|  
  c.access_key_id = ENV['AWS_ACCESS_KEY_ID']
  c.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
  c.bucket = ENV['AWS_BUCKET']
  c.region = ENV['AWS_REGION']

Because this is going to lead you to this url end: https://bucket.us-west-2.amazonaws.com you can see it here: s3_file_field code

So instead of it, please add the AWS_REGION var to your fog configuration.

  config.paperclip_defaults = {
    :storage => :fog,
    :fog_credentials => {
      aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
      aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
      provider: ENV['FOG_PROVIDER'],
      region: ENV['AWS_REGION']
    fog_directory: ENV['FOG_DIRECTORY']

Some guy found it fog issue

I spent so much time trying to figure this out, so my advice is: "Sometimes the issue is not where you think is happening, sometimes you need to read github issues instead".

And that's all folks!, if you liked or if this was of any help, please follow me on twitter @zazvick.

Victor Velazquez

Coder, Musician, Startups, Passionate Dancer & Life Lover. Director of Engineering at MagmaLabs, Co-founder of Web Dev Talks, Co-founder of Voltaire, Co-founder of Paqkit, Ex-co-founder of Zaznova.

Subscribe to The zazvick's blog

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!