Search code examples
uploadamazon-s3carrierwavermagickfog

Unable to save file to Amazon S3 when using carrierwave


SEE UPDATE BELOW!

I am having problems after I upload an image file to Amazon S3 and then try to save the file.

I use direct_fog_url(with_path: true) to get the the url of the image uploaded. I then get the following error:

ActiveRecord::RecordInvalid Validation failed: Image could not download file

I saw these two possible solutions:

https://github.com/jnicklas/carrierwave/issues/700

http://www.github.com/jnicklas/carrierwave/issues/888

But neither one seems to work.

Im using the older deleted command: overwriting method process_uri (enter link description here):

def process_uri(uri) 
 URI.parse(URI.escape(URI.unescape(uri)).gsub("[", "%5B").gsub("]", "%5D").gsub("+", "%2B"))
end

In my application I am using the following Gems:

gem 'fog'

gem 'carrierwave'

gem 'carrierwave_direct'

gem 'rmagick'

Thanks!

UPDATE: After implementing @Alex's answer below we resolved that problem but now when we do the upload we get the following error:

Excon::Errors::MovedPermanently

PermanentRedirect The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.


Solution

  • For your Excon::Errors::MovedPermanently issue, make sure that you have the right data center region configured in your carrierwave.rb file. For example, if you're hosted on us-west, your region needs to be set to us-west.