简体   繁体   English

版本问题:Rails 3.1 RC 中的 Errno::ENOENT

[英]Problem with versions: Errno::ENOENT in Rails 3.1 RC

I am using Rails 3.1 RC and Carrierwave 0.5.4.我正在使用 Rails 3.1 RC 和 Carrierwave 0.5.4。 Don't know if this is an issue with 3.1.不知道是不是3.1的问题。

I verified that the path and file exists (http://bucket_name.s3.amazonaws.com/unencoded/users/1/photos/test.gif) in my S3 bucket.我验证了我的 S3 存储桶中存在路径和文件 (http://bucket_name.s3.amazonaws.com/unencoded/users/1/photos/test.gif)。

When I do:当我做:

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

Error I get:我得到的错误:

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

Why is Carrierwave trying to access the local dir instead of S3?为什么 Carrierwave 尝试访问本地目录而不是 S3?

My initializer looks like:我的初始化程序看起来像:

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

My uploader class looks like:我的上传器 class 看起来像:

# 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

Full stack trace:完整的堆栈跟踪:

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>

In my uploader class, if I remove the versions, the upload succeeds without any errors.在我的上传器 class 中,如果我删除版本,则上传成功且没有任何错误。

Anyone coming across the same problem?有人遇到同样的问题吗?

Hmmmm, I don't know exactly what the problem is, but I switched my gem file from:嗯,我不知道到底是什么问题,但我从以下位置切换了我的 gem 文件:

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

to

gem 'carrierwave', '0.5.4'

The problem seems to have gone away.问题似乎已经消失了。 There is something definitely wrong with the master version...主版肯定有问题...

Hope this helps someone who comes across the same issue on Rails 3.1 RC and Carrierwave.希望这对在 Rails 3.1 RC 和 Carrierwave 上遇到相同问题的人有所帮助。

Following command should do the trick.以下命令应该可以解决问题。 On Ubuntu it is like:在 Ubuntu 上是这样的:

sudo apt-get install imagemagick

Its your code here这是你的代码

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

Your app is using that for processing the images.您的应用程序正在使用它来处理图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM