我正在使用 Rails 3.1 RC 和 Carrierwave 0.5.4。不知道是不是3.1的问题。
我验证了我的 S3 存储桶中存在路径和文件 (http://bucket_name.s3.amazonaws.com/unencoded/users/1/photos/test.gif)。
当我做:
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/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/sanitized_file.rb:157:in `initialize'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/sanitized_file.rb:157:in `open'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/sanitized_file.rb:157:in `read'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/storage/fog.rb:230:in `store'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/storage/fog.rb:79:in `store!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/store.rb:59:in `block in store!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:17:in `with_callbacks'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/store.rb:58:in `store!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `block in store_versions!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `each'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `store_versions!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:18:in `block in with_callbacks'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:18:in `each'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/callbacks.rb:18:in `with_callbacks'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/store.rb:58:in `store!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/bundler/gems/carrierwave-0d2e9ee87060/lib/carrierwave/uploader/versions.rb:193:in `block in store_versions!'
... 16 levels...
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:183:in `transaction'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:208:in `transaction'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:246:in `save!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/persistence.rb:168:in `block in update_attributes!'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/connection_adapters/abstract/database_statements.rb:183:in `transaction'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:208:in `transaction'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/activerecord-3.1.0.rc1/lib/active_record/persistence.rb:166:in `update_attributes!'
from (irb):5
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:44:in `start'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/gems/railties-3.1.0.rc1/lib/rails/commands/console.rb:8:in `start'
from /Users/Chris/.rvm/gems/ruby-1.9.2-p136@railspre/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>
在我的上传器类中,如果我删除版本,上传成功且没有任何错误。
有人遇到同样的问题吗?