Ruby on rails 3 Carrierwave直接上传到s3,sidekiq验证失败
遵循Ryan Bates教程,使用CarrierWave和Sidekiq的后台作业直接上传到S3 我在sidekiq日志的后台工作程序中看到以下错误Ruby on rails 3 Carrierwave直接上传到s3,sidekiq验证失败,ruby-on-rails-3,upload,amazon-s3,carrierwave,sidekiq,Ruby On Rails 3,Upload,Amazon S3,Carrierwave,Sidekiq,遵循Ryan Bates教程,使用CarrierWave和Sidekiq的后台作业直接上传到S3 我在sidekiq日志的后台工作程序中看到以下错误 2012-11-10T14:33:56Z 44401 TID-owd2xrzdg WARN: {"retry"=>true, "queue"=>"default", "class"=>"Article::ImageWorker", "args"=>[44, "uploads/d8850e90-0d6d-0130-fe
2012-11-10T14:33:56Z 44401 TID-owd2xrzdg WARN: {"retry"=>true, "queue"=>"default", "class"=>"Article::ImageWorker", "args"=>[44, "uploads/d8850e90-0d6d-0130-fecf-3c0754129341/mkv5E.jpg"], "jid"=>"8add5079541725ad30550f9c", "error_message"=>"Validation failed: Image could not download file", "error_class"=>"ActiveRecord::RecordInvalid", "failed_at"=>"2012-11-10T14:29:15Z", "retry_count"=>4, "retried_at"=>2012-11-10 14:33:56 UTC}
2012-11-10T14:33:56Z 44401 TID-owd2xrzdg WARN: Validation failed: Image could not download file
2012-11-10T14:33:56Z 44401 TID-owd2xrzdg WARN: /Users/kgoddard/.rvm/gems/ruby-1.9.3-head/gems/activerecord-3.2.8/lib/active_record/validations.rb:56:in `save!'
这是我的上传器
class ImageUploader < CarrierWave::Uploader::Base
# Include CarrierWave direct uploader to background upload task.
include CarrierWaveDirect::Uploader
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
# Choose what kind of storage to use for this uploader:
# storage :file
storage :fog
# Set the mimetype of the upload incase it is incorrect.
include CarrierWave::MimeTypes
process :set_content_type
process :resize_to_limit => [640, 640]
version :thumb do
process :resize_to_fill => [160, 120]
end
end
快照控制器显示负责呈现上载表单的操作
# GET /shoots/1
# GET /shoots/1.json
def show
# TODO: is this the best way to prevent users from accessing not owned resources.
@shoot = Shoot.find(params[:id])
@uploader = Article.new.image
@uploader.success_action_redirect = new_admin_article_url
if @shoot
respond_to do |format|
format.html # show.html.erb
end
else
redirect_to shoots_path, alert: 'No shoot found with id: #{params[:id]}'
end
end
显示动作上传器的表单
<div class="hero-unit">
<h2><%= @shoot.name %></h2>
<p><%= @shoot.overview %></p>
<p>This shoot was taken on <%= @shoot.shoot_date %></p>
<%= direct_upload_form_for @uploader do |f| %>
<p><%= f.file_field :image, multiple: true, name: "article[image]" %></p>
<p><%= f.submit "Add Media", :class => "btn btn-primary" %></p>
<% end %>
</div><!-- /hero-unit -->
这张照片是拍的
“btn btn主要”%>
结果是我的bucket名称无效。。。确保您的bucket名称仅包含字母、数字和破折号。此外,您不需要说storage:fog--CarrierWave Direct默认情况下会这样做。
# GET /shoots/1
# GET /shoots/1.json
def show
# TODO: is this the best way to prevent users from accessing not owned resources.
@shoot = Shoot.find(params[:id])
@uploader = Article.new.image
@uploader.success_action_redirect = new_admin_article_url
if @shoot
respond_to do |format|
format.html # show.html.erb
end
else
redirect_to shoots_path, alert: 'No shoot found with id: #{params[:id]}'
end
end
<div class="hero-unit">
<h2><%= @shoot.name %></h2>
<p><%= @shoot.overview %></p>
<p>This shoot was taken on <%= @shoot.shoot_date %></p>
<%= direct_upload_form_for @uploader do |f| %>
<p><%= f.file_field :image, multiple: true, name: "article[image]" %></p>
<p><%= f.submit "Add Media", :class => "btn btn-primary" %></p>
<% end %>
</div><!-- /hero-unit -->