Tôi đang cố gắng phát triển các tệp tải lên trực tiếp lên S3 cho ứng dụng của mình. Tôi đang làm theo hướng dẫn github cho điều này và tất cả mọi thứ là nhiều hơn hoặc ít ok nhưng nhận được một thông báo lỗi khi cố gắng để làm cho chế biến bài viết.save_and_process post processing 403 Forbidden Carrierwave_direct S3 Fog
tôi đã làm như sau:
Tôi có một mô hình activerecord gọi clip.rb:
class Clip < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true
mount_uploader :avatar, AvatarUploader
attr_accessible :id, :avatar, :name, :clipat_file_name, :attachable_id, :attachable_type, :clipat, :project_id, :user_id, :path, :parent_id,
def save_and_process_avatar(options = {})
if options[:now] or 1==1
self.remote_avatar_url = avatar.direct_fog_url(:with_path => true)
save
else
Resque.enqueue(AvatarProcessor, attributes)
end
end
Sau đó, tôi có một người tải lên: avatar_uploader.rb
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
include CarrierWaveDirect::Uploader
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}" #I removed /#{model.id} from the template because it creates an empty directory on the server. But If I put it back, the same problem remains
end
version :thumb do
process :resize_to_limit => [50, 50]
end
end
và một bộ điều khiển avatar :
class AvatarsController < ApplicationController
def new
@uploader = Clip.new.avatar
@uploader.success_action_redirect = 'http://localhost:3000/clips'
end
end
và cuối cùng clip_controller tôi:
class ClipsController < ApplicationController
def index
if params[:key]
key=params[:key].split("/")
clip = Clip.new
clip.attachable_id = key[3]
clip.attachable_type = "Pmdocument"
clip.key = params[:key]
# clip.save
clip.save_and_process_avatar
end
@clips = Clip.where("avatar is not null")
respond_to do |format|
format.html # index.html.erb
format.json { render json: @clips.collect { |p| p.to_jq_upload }.to_json }
end
end
Khi tôi tải lên một tập tin, nếu tôi chỉ cần lưu của tôi "clip", mọi thứ đều ok. Nếu tôi sử dụng phương pháp save_and_process Tuy nhiên, một lỗi phát sinh tại dòng: self.remote_avatar_url = avatar.direct_fog_url (: with_path => true)
Đây là thông báo lỗi:
OpenURI::HTTPError (403 Forbidden):
app/models/clip.rb:38:in `save_and_process_avatar'
app/controllers/clips_controller.rb:22:in `index'
Rendered /Users/nico/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms)
Rendered /Users/nico/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.2ms)
Rendered /Users/nico/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (5.2ms)
Tôi đã treo trên này trong hai ngày như vậy, bất kỳ trợ giúp sẽ được đánh giá rất nhiều !!! Cảm ơn!!! Nicolas.
Bạn đang nhận được gì từ kết quả của dòng này? 'self.remote_avatar_url = avatar.direct_fog_url (: with_path => true)' – pschuegr
Tôi đã ngừng làm việc với Carrierwave trong một thời gian dài (quay lại Paperclip). Vì vậy, tôi không thể trả lời câu hỏi của bạn. Lấy làm tiếc... – ndemoreau