我正在使用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>
在我的上传器类中,如果删除版本,则上传成功且没有任何错误。
有人遇到同样的问题吗?
答案 0 :(得分:1)
gem 'carrierwave', :git => 'http://github.com/jnicklas/carrierwave.git'
到
gem 'carrierwave', '0.5.4'
这个问题似乎已经消失了。主版本肯定有问题......
希望这有助于在Rails 3.1 RC和Carrierwave上遇到同样问题的人。
答案 1 :(得分:0)
这是你的代码
def cache_dir
"#{Rails.root}/tmp/uploads"
end
您的应用正在使用它处理图片。
答案 2 :(得分:0)
以下命令应该可以解决问题。在Ubuntu上它就像:
sudo apt-get install imagemagick