Rails 3 Carrierwave-Fog-S3 错误:预期(200) <=>实际(404未找到)

发布于 2024-11-08 13:58:25 字数 1312 浏览 0 评论 0 原文

我正在使用 Carrerwave 0.5.3,在图片控制器的 Create 方法中调用 Picture.save 时出现 404 错误。根据 lib/rierwave/storage/s3.rb 中的说明,我的初始化文件 (config/initializers/rierwave_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

在 photo_uploader.rb 中,我有:

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

确切的错误:

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

我在这里发现了一个稍微类似的问题 < a href="https://stackoverflow.com/questions/5481523/rierwave-and-s3-with-heroku-error-undefined-method-fog-credentials">Carrierwave 和 s3 带有 heroku 错误未定义方法 `fog_credentials='< /a> .但按照我现在的方式设置显然在这种情况下有效。不幸的是它不适合我。

我已将一张图片放入我的存储桶中,并将权限设置为公开,并且可以通过浏览器访问该图片。所以 AWS S3 方面的事情似乎正在发挥作用。

不知道下一步该去哪里。有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞别 2024-11-15 13:58:25

好吧,我睡了一晚,第二天回来,一切都很好。不知道为什么它突然开始工作。

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

身边 2024-11-15 13:58:25

确保您的文件名经过清理,并且不包含空格或斜杠等无效字符。
要清理字符串,您可以对其调用 gsub 方法。以下方法调用将清理文件以上传到 S3、Google Cloud Storage 等。

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

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.\-]/, '_')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文