vendredi 2 janvier 2015

AWS says my bucket is "us-west-2" but my paperclip on rails suggest otherwise?

I have a Rails app that run PaperClip fine locally, but I am trying to get AWS S3 storage so it can work fully once I deploy to Heroku. The object that that I am attaching images to, with the paperclip gem, are "products." Currently, I am getting a AWS::S3::Errors::PermanentRedirect in ProjectsController#createerror that says "The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint."


From my googling it seems that this is often a result of specifying the wrong region for the S3 bucket. However, when I view my S3 bucket on AWS the url (http://ift.tt/1hdk2kv) states that it is a us-west-2 region.


All of my code has that as that as the specified region, but I am still getting the error.


Using Relevant Gems



gem "paperclip"
gem 'aws-sdk'


My Model



class Project < ActiveRecord::Base
has_attached_file :avatar,
:storage => :s3,
:bucket => 'BUCKET_NAME_HERE',
:s3_credentials => {
:access_key_id => 'ACCESS_KEY_HERE',
:secret_access_key => 'SECRET_KEY_HERE'
},
:s3_host_name => 's3-us-west-2.amazonaws.com',
:url => "/:image/:id/:style/:basename.:extension",
:path => ":image/:id/:style/:basename.:extension"
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
end


Both my development.rb and production.rb



config.paperclip_defaults = {
:storage => :s3,
:s3_host_name => 's3-us-west-2.amazonaws.com'
}


My s3.yml file



development:
access_key_id: 'ACCESS_KEY_HERE'
secret_access_key: 'SECRET_KEY_HERE'
bucket: 'BUCKET_NAME_HERE'

production:
access_key_id: 'ACCESS_KEY_HERE'
secret_access_key: 'SECRET_KEY_HERE'
bucket: 'BUCKET_NAME_HERE'


Relevant Controller with Create Path



class ProjectsController < ApplicationController

def create
@project = Project.new(project_params)
if @project.save
redirect_to '/projects'
else
redirect_to '/500'
end
end

def project_params
params.require(:project).permit(:name, :description, :avatar)
end

end


What am I doing wrong and how do I fix it?





Aucun commentaire:

Enregistrer un commentaire