gpt4 book ai didi

ruby-on-rails-3 - Carrierwave 直接上传到 s3,sidekiq 验证失败

转载 作者:行者123 更新时间:2023-12-04 05:24:41 27 4
gpt4 key购买 nike

遵循关于使用 CarrierWave 和 Sidekiq 后台作业直接上传到 S3 的 Ryan Bates 教程。

我在 sidekiq 日志的后台工作人员中看到以下错误。

    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

文章模型
class Article < ActiveRecord::Base
attr_accessible :orientation, :shoot_id, :image
belongs_to :shoot
mount_uploader :image, ImageUploader

after_save :enqueue_image

def image_name
File.basename(image.path || image.filename) if image
end

def enqueue_image
ImageWorker.perform_async(id, key) if key.present?
end

class ImageWorker
include Sidekiq::Worker

def perform(id, key)
article = Article.find(id)
article.key = key
article.remote_image_url = article.image.direct_fog_url(:with_path => true)
article.save!
article.update_column(:image_processed, true)
end

end

end

载波配置
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => ENV["AWS_ACCESS_KEY_ID"], # required
:aws_secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"], # required
:region => 'eu-east-1' # optional, defaults to 'us-east-1'
}
config.fog_directory = ENV["AWS_S3_BUCKET"] # required
end

Shoot Controller 显示负责渲染上传表单的 Action
  # 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

显示 Action 上传器的表单
<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 -->

最佳答案

原来我的存储桶名称无效...确保您的存储桶名称仅包含字母、数字和破折号。

关于ruby-on-rails-3 - Carrierwave 直接上传到 s3,sidekiq 验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13323061/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com