2011-06-03 31 views
0

變量Errno :: ENOENT我用Rails 3.1 RC和Carrierwave 0.5.4。不知道這是否是3.1的問題。問題的版本:對Rails 3.1 RC

我驗證的路徑和文件存在(http://bucket_name.s3.amazonaws.com/unencoded/users/1/photos/test.gif)在我的S3存儲桶。

當我這樣做:

Photo.first.update_attributes!(:job_state => 'processing', :remote_attachment_url => 'http://bucket_name.s3.amazonaws.com/unencoded/users/1/photos/test.gif') 

錯誤,我得到:

Errno::ENOENT: No such file or directory - /Users/Chris/Sites/site_name/tmp/uploads/20110603-1813-612-6936/small_test.gif 

爲什麼Carrierwave試圖訪問本地目錄,而不是S3?

我的初始化是這樣的:

CarrierWave.configure do |config| 
    config.fog_credentials = { 
    :provider    => 'AWS',  # required 
    :aws_access_key_id  => APP_CONFIG['amazon_access_key_id'],  # required 
    :aws_secret_access_key => APP_CONFIG['amazon_secret_access_key']  # required 
    } 
    config.fog_directory = 'bucket_name'      # required 
    config.fog_host  = 'http://cdn.site_name.com'   # optional, defaults to nil 
    config.fog_public  = true         # optional, defaults to true 
    config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {} 
end 

我上傳類的樣子:

# encoding: utf-8 

class PhotoUploader < CarrierWave::Uploader::Base 
    include CarrierWave::MiniMagick 

    # Choose what kind of storage to use for this uploader: 
    storage :fog 

    # Override the directory where uploaded files will be stored. 
    # This is a sensible default for uploaders that are meant to be mounted: 
    def store_dir 
    "uploads/users/#{model.user.id}/#{model.class.to_s.underscore}s/#{model.id}" 
    end 

    # Create different versions of your uploaded files: 
    version :small do 
    process :resize_to_fill => [53,53] 
    end 
    version :medium do 
    process :resize_to_fill => [106,106] 
    end 
    version :large do 
    process :resize_to_fill => [212,212] 
    end 

    # Add a white list of extensions which are allowed to be uploaded. 
    # For images you might use something like this: 
    def extension_white_list 
    %w(jpg jpeg gif png) 
    end 

    # https://github.com/jnicklas/carrierwave/wiki 
    # Heroku has a read-only filesystem, so uploads must be stored on S3 and cannot be cached in the public 
    # directory. You can work around the caching limitation by setting the cache_dir in your Uploader classes 
    # to the tmp directory. 
    def cache_dir 
    "#{Rails.root}/tmp/uploads" 
    end 
end 

完整的堆棧跟蹤:

Errno::ENOENT: No such file or directory - /Users/Chris/Sites/site_name/tmp/uploads/20110603-1827-5843-3673/small_test.gif 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/sanitized_file.rb:157:in `initialize' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/sanitized_file.rb:157:in `open' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/sanitized_file.rb:157:in `read' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/storage/fog.rb:230:in `store' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/storage/fog.rb:79:in `store!' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/store.rb:59:in `block in store!' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/store.rb:58:in `store!' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `block in store_versions!' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `each' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `store_versions!' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:18:in `block in with_callbacks' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:18:in `each' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:18:in `with_callbacks' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/store.rb:58:in `store!' 
from /Users/Chris/.rvm/gems/[email protected]/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `block in store_versions!' 
... 16 levels... 
from /Users/Chris/.rvm/gems/[email protected]/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:183:in `transaction' 
from /Users/Chris/.rvm/gems/[email protected]/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:208:in `transaction' 
from /Users/Chris/.rvm/gems/[email protected]/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status' 
from /Users/Chris/.rvm/gems/[email protected]/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:246:in `save!' 
from /Users/Chris/.rvm/gems/[email protected]/gems/activerecord-3.1.0.rc1/lib/active_record/persistence.rb:168:in `block in update_attributes!' 
from /Users/Chris/.rvm/gems/[email protected]/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status' 
from /Users/Chris/.rvm/gems/[email protected]/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:183:in `transaction' 
from /Users/Chris/.rvm/gems/[email protected]/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:208:in `transaction' 
from /Users/Chris/.rvm/gems/[email protected]/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status' 
from /Users/Chris/.rvm/gems/[email protected]/gems/activerecord-3.1.0.rc1/lib/active_record/persistence.rb:166:in `update_attributes!' 
from (irb):5 
from /Users/Chris/.rvm/gems/[email protected]/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:44:in `start' 
from /Users/Chris/.rvm/gems/[email protected]/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:8:in `start' 
from /Users/Chris/.rvm/gems/[email protected]/gems/railties-3.1.0.rc1/lib/rails/commands.rb:40:in `<top (required)>' 
from script/rails:6:in `require' 
from script/rails:6:in `<main> 

在我的上傳類,如果我刪除版本,上傳成功沒有任何錯誤。

任何人在同樣的問題來了嗎?

回答

1

Hmmmm,我不知道到底是什麼問題,但我打開我的寶石文件來自:

gem 'carrierwave', :git => 'http://github.com/jnicklas/carrierwave.git' 

gem 'carrierwave', '0.5.4' 

這個問題似乎已經消失。也有一些是絕對錯誤與主版本...

希望這可以幫助別人誰在同樣的問題來到on Rails的3.1 RC和Carrierwave。

0

,是你的代碼在這裏

def cache_dir 
    "#{Rails.root}/tmp/uploads" 
    end 

您的應用使用的是用於處理圖像。

+0

我在我的上傳類中註釋掉了這個塊。重新啓動Rails服務器和Rails控制檯。還是一樣的錯誤。 – 2011-06-04 08:39:54

0

下面的命令應該做的伎倆。在Ubuntu上它是這樣的:

sudo apt-get install imagemagick