ruby-on-rails-3file-uploadcarrierwaverackspacefog

Fog::Storage::Rackspace::NotFound error when using Carrierwave to upload to Rackspace


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?


Solution

  • 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.'