2
votes

Everyone: I already searched the error before I posted this to Stackoverflow, so no need to point me to this: groups.google.com/forum/?fromgroups=#!topic/carrierwave/ It's not the same problem.

I'm using Carrierwave so users can upload files to my Rackspace container. But when I Submit from my site (on my local machine, still in test mode), I get a Fog::Storage::Rackspace::NotFound app/controllers/authors_controller.rb:8:in `update' error. My Rackspace container is called kontainer.ofstuff. Here's my code:

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

model author.rb

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

  mount_uploader :pic, PicUploader

  def dostuff
  end
end

carrierwave.rb is in the config/initializers directory

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

controller 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

edit.html.erb:

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

When I had this code 'uploading'/storing to a file, this worked fine. Perhaps f.submit does not work with Carrierwave? If not...where do I find the correct code for submitting?

Any ideas what the trouble is?

4
I've never used Rackspace, but are you giving the correct container name ? You might have the same error as groups.google.com/forum/?fromgroups=#!topic/carrierwave/… - pjam
Already saw that topic and I mentioned my container name above. So, no, that's not the issue I am having. I even tried making a new container, using new URL, etc. and still the same problem. And since containers don't recognize directories (only objects), I tried messing with taking directory names out of def store_dir "#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end with no luck. - ThinQtv

4 Answers

2
votes

I kind of had the same problem, but for me it turned out that I needed to make the container multiple times with the same name but for all the regions. I have no idea why it worked after that, but I guess that's something to try?

Update 11-7-2012

So Carrierwave had some updates since my answer. I was able to get a more stable upload through some trial and error. Here's what I did:

  1. Updated carrierwave gem to 0.7.0
  2. Logged into Rackspace and deleted containers for all the regions.
  3. Added one single container. It doesn't matter which region, whichever is more applicable to you.
  4. Made the container public (Enable CDN)
  5. Copied the Public HTTP CDN link for the container
  6. Updated my /config/initalizers/carrierwave.rb file:

    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
    

As a note: I configured my uploader to use storage:fog when the environment is production or staging. Otherwise I use the default local file system.

The main thing to note is that carrierwave changed the config 'fog_host' to 'asset_host.'

4
votes

I also got this error. Solved by adding this to uploaded code:

class MyUploader < CarrierWave::Uploader::Base

  ....

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

end
1
votes

For what it's worth: I was having this same problem after migrating from AWS to Rackspace. The error was being thrown because part of updating the file is deleting the old file. In my case, the old file was on S3, not on Rackspace, so carrierwave got upset.

0
votes

This seemed to be a case of Wait A Few Months & install updated gem. The problem pretty much went away. I also got rid of Rackspace & went to Amazon S3, although I had tried S3 earlier with the same issues. I'm crediting the solution to the updated Carrierwave gem.