0

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.

Danconia
  • 543
  • 2
  • 12
  • 28

2 Answers2

1

Have you found a solution to this problem yet?

I'm facing the same problem here, I'm trying to fetch a remote URL with carrierwave (not on S3) and I get the notorious 'could not download file' error:

    Validation failed: Image could not download file
    [...]/gems/activerecord-3.2.9/lib/active_record/validations.rb:56:in `save!'

Could you post your URL to see what special characters there are?

EDIT: I found a solution. My case required that I did not change or escape the uri at all. I found that by adding 'return' to the 'def process_uri(uri)' method it works just fine. Just in case this is useful to someone else, this is my overriding method in my uploader class:

    def process_uri(uri)
      return URI.parse(uri)
    end
Alex
  • 453
  • 5
  • 14
  • This seems to resolve the first issue for us, but now we are getting a new error: PermanentRedirect The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. – Danconia Nov 30 '12 at 21:47
  • Just to clarify, adding "return" shouldn't make any difference in Ruby code. The last command in the method will automatically return. – Jeremy Baker Nov 30 '12 at 22:45
1

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.

Jeremy Baker
  • 3,986
  • 3
  • 24
  • 27
  • What you said was the issue. It turns out that the problem was legacy issues with AWS - http://stackoverflow.com/questions/13691881/301-moved-permanently-after-s3-uploading – Danconia Dec 06 '12 at 23:15