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.

4

2 に答える 2

1

Excon::Errors::MovedPermanently の問題については、carrierwave.rb ファイルで適切なデータ センター リージョンが構成されていることを確認してください。たとえば、us-west でホストされている場合、リージョンを us-west に設定する必要があります。

于 2012-11-30T22:15:28.983 に答える
1

この問題の解決策は見つかりましたか?

ここで同じ問題に直面しています。carrierwave (S3 ではなく) でリモート URL を取得しようとしていますが、悪名高い「ファイルをダウンロードできませんでした」というエラーが表示されます。

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

URL を投稿して、どのような特殊文字があるかを確認していただけますか?

編集:解決策を見つけました。私のケースでは、uri をまったく変更したりエスケープしたりしないことが必要でした。「def process_uri(uri)」メソッドに「return」を追加すると、問題なく動作することがわかりました。これが他の誰かに役立つ場合に備えて、これは私のアップローダ クラスのオーバーライド メソッドです。

    def process_uri(uri)
      return URI.parse(uri)
    end
于 2012-11-28T14:28:31.743 に答える