Rails 3 Carrierwave-Fog-S3 error: Expected(200) <=> Actual(404 Not Found)

时间秒杀一切 提交于 2019-12-10 18:07:17

问题


I'm using Carrerwave 0.5.3 and getting a 404 error on my call to Picture.save in the Create method of my picture controller. Per the instructions in lib/carrierwave/storage/s3.rb I have the following in my initialization file (config/initializers/carrierwave_fog.rb):

CarrierWave.configure do |config|
     config.s3_access_key_id = "xxxxx"
     config.s3_secret_access_key = "xxxxx"
     config.s3_bucket = "mybucket"  #already created in my S3 account
end

In photo_uploader.rb I have:

class PhotoUploader < CarrierWave::Uploader::Base
  include CarrierWave::RMagick
  storage :s3
  def store_dir
    "uploads"  # already created in my s3 account
  end
  def cache_dir
    "uploads/cache"  #already created in my s3 account
  end
end

The exact error:

Excon::Errors::NotFound in PicturesController#create
Expected(200) <=> Actual(404 Not Found)
  request => {:expects=>200}
  response => #<Excon::Response:0x00000104a72448 @body="", @headers={}, @status=404>

I found a slightly similar question here Carrierwave and s3 with heroku error undefined method `fog_credentials=' . But setting things up the way I have it now apparently worked in that case. Unfortunately it didn't for me.

I've put a picture in my bucket and set the permissions to public and can access the picture via a browser. So things on the AWS S3 side seem to be working.

Not sure where to go next. Any ideas?


回答1:


Well, I slept on this for a night came back the next day and all was good. Not sure why it suddenly started working.




回答2:


Make sure your file names are sanitized and do not contain invalid characters like spaces or slashes. To sanitize a string you can call the gsub method on it. The following method call will sanitize files for upload to S3, Google Cloud Storage etc.

"Invalid\ file *& | | name.png".gsub(/[^0-9A-z.\-]/, '_')


来源:https://stackoverflow.com/questions/6068041/rails-3-carrierwave-fog-s3-error-expected200-actual404-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!