2

大家:在将它发布到 Stackoverflow 之前,我已经搜索了该错误,因此无需向我指出:groups.google.com/forum/?fromgroups=#!topic/carrierwave/ 这不是同一个问题。

我正在使用 Carrierwave,因此用户可以将文件上传到我的 Rackspace 容器。但是当我从我的站点提交时(在我的本地机器上,仍处于测试模式),我得到一个Fog::Storage::Rackspace::NotFound app/controllers/authors_controller.rb:8:in `update' 错误。我的 Rackspace 容器称为 kontainer.ofstuff。这是我的代码:

pic_uploader.rb:

class PicUploader < CarrierWave::Uploader::Base

  include Rails.application.routes.url_helpers
  storage :fog

  def store_dir
    "#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
end

模型作者.rb

class Author < ActiveRecord::Base
  attr_accessible :stuff, :profilepic

  mount_uploader :pic, PicUploader

  def dostuff
  end
end

carrierwave.rb 位于 config/initializers 目录中

CarrierWave.configure do |config|

  config.storage = :fog
  config.fog_credentials = {
    :provider           => 'Rackspace',
    :rackspace_username => 'myusername',
    :rackspace_api_key  => '98765asecretnumber3'
  })
  config.fog_directory = 'kontainer.ofstuff'
  config.fog_host = 'https://34567secretnumberiiiii.ssl.cf2.rackcdn.com'
end

控制器 authors_controller.rb

class AuthorsController < ApplicationController

  def update
    @author = Author.find(params[:id])
    @booklist = Book.where(:author_id => @author.id)
#line 7
    if @author.update_attributes(params[:author])
      sign_in @author
      redirect_to @author
    else
      render 'profileinfo'
    end
  end
end

编辑.html.erb:

<%= f.file_field :pic %>
<%= f.submit "Save Author Info" %> 

当我将此代码“上传”/存储到文件时,效果很好。也许 f.submit 不适用于 Carrierwave?如果不是...我在哪里可以找到正确的提交代码?

有什么想法吗?

4

4 回答 4

4

我也遇到了这个错误。通过将此添加到上传的代码来解决:

class MyUploader < CarrierWave::Uploader::Base

  ....

  def remove!
    begin
      super
    rescue Fog::Storage::Rackspace::NotFound
    end
  end

end
于 2013-05-19T09:52:15.503 回答
2

我有同样的问题,但对我来说,我需要多次使用相同的名称制作容器,但适用于所有区域。我不知道为什么在那之后它会起作用,但我想这是可以尝试的?

2012 年 11 月 7 日更新

因此,自从我回答之后,Carrierwave 有了一些更新。通过一些试验和错误,我能够获得更稳定的上传。这是我所做的:

  1. 将载波 gem 更新到 0.7.0
  2. 登录 Rackspace 并删除所有区域的容器。
  3. 添加了一个容器。不管哪个地区更适合你。
  4. 公开容器(启用 CDN)
  5. 复制了容器的公共 HTTP CDN 链接
  6. 更新了我的 /config/initializers/carrierwave.rb 文件:

    CarrierWave.configure do |config|
      config.fog_credentials = {
        :provider           => 'Rackspace',
        :rackspace_username => '[Your Rackspace Username]',
        :rackspace_api_key  => '[Your Rackspace API key]'
      }
      config.fog_directory = '[The name of the container you created]'
    
      if Rails.env.production? || Rails.env.staging?
        config.asset_host = '[The Public HTTP CDN url for the container]'
      end
    end
    

注意:我将上传器配置为在生产或登台环境时使用 storage:fog。否则我使用默认的本地文件系统。

主要需要注意的是,carrierwave 将配置“fog_host”更改为“asset_host”。

于 2012-10-25T20:47:22.627 回答
1

值得一提的是:从 AWS 迁移到 Rackspace 后,我遇到了同样的问题。由于更新文件的一部分正在删除旧文件,因此引发了错误。就我而言,旧文件在 S3 上,而不是在 Rackspace 上,因此carrierwave 很不高兴。

于 2012-11-13T22:35:45.117 回答
0

这似乎是等待几个月并安装更新的 gem 的情况。问题几乎消失了。我也摆脱了 Rackspace 并转到了 Amazon S3,尽管我之前曾尝试过 S3,但也遇到了同样的问题。我将解决方案归功于更新的 Carrierwave gem。

于 2013-09-19T12:31:08.650 回答