2012-02-03 15 views
5

मैं अपने ऐप के लिए S3 पर सीधे फ़ाइल अपलोड लोड करने का प्रयास कर रहा हूं। मैं इसके लिए github ट्यूटोरियल का पालन कर रहा हूं और सबकुछ कम या ज्यादा ठीक है लेकिन पोस्ट प्रोसेसिंग करने का प्रयास करते समय त्रुटि संदेश प्राप्त करें।save_and_process पोस्ट प्रोसेसिंग 403 निषिद्ध Carrierwave_direct S3 धुंध

मैं एक ActiveRecord मॉडल 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 

तो मैं एक अपलोड करने वाले हैं: 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 

और एक अवतार नियंत्रक

मैं निम्नलिखित किया :

class AvatarsController < ApplicationController 
    def new 
    @uploader = Clip.new.avatar 
    @uploader.success_action_redirect = 'http://localhost:3000/clips' 
    end 
end 

और अंत में मेरी clip_controller:

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 

मैं एक फ़ाइल अपलोड करते हैं, अगर मैं सिर्फ अपनी "क्लिप" बचाने के लिए, सब कुछ ठीक है। अगर मैं तथापि save_and_process विधि का उपयोग करें, एक त्रुटि लाइन पर उठता है: self.remote_avatar_url = avatar.direct_fog_url

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) 

मैं किया गया है: (: with_path => true)

यह त्रुटि संदेश है दो दिनों के लिए इस पर लटका, तो किसी भी मदद की सराहना की जाएगी !!! धन्यवाद!!! निकोलस।

+0

इस लाइन के परिणामस्वरूप आप क्या प्राप्त कर रहे हैं? 'self.remote_avatar_url = avatar.direct_fog_url (: with_path => true)' – pschuegr

+0

मैंने कैरियरवेव के साथ लंबे समय से काम करना बंद कर दिया है (पेपरक्लिप पर वापस)। तो मैं आपके प्रश्न का उत्तर नहीं दे सकता। माफ़ कीजिये... – ndemoreau

उत्तर

2

मेरी शर्त यह है कि self.remote_avatar_url पर प्रदान किया गया URL गलत है। मुझे यह वही समस्या थी और कोड जो CWDirect मणि प्रदान करता है, मेरे लिए काम नहीं करता और मुझे एक गलत यूआरएल दिया, इस प्रकार कैरियरवेव छवि को डाउनलोड और संसाधित नहीं कर सका। संपूर्ण 403 निषिद्ध त्रुटि संदेश अमेज़ॅन से एक बकवास संदेश था - इससे किसी को यह विश्वास होता है कि अनुमतियों में कुछ गड़बड़ है; मेरे मामले में अनुमतियों के साथ बिल्कुल कुछ भी गलत नहीं था। यह सिर्फ इतना था कि वहां कोई छवि नहीं थी। यहाँ कोड है कि मेरे लिए यह काम कर रहे हो गया है, नोटिस मैं बदल दिया है कैसे यूआरएल बनाई है:

def save_and_process_image(options = {}) 
if options[:now] 
    # debugger 
    self.remote_image_url = image.direct_fog_url+self.key # OLD CODE THAT AINT WORKIN! --> image.direct_fog_url(:with_path => true) 
    save 
else 
    # Resque.enqueue(AvatarProcessor, attributes) 
    # TODO: Implement background processing 
end 
end 

ध्यान दें कि मेरी घुड़सवार फ़ील्ड का नाम image और नहीं avatar है।

मैं कैसे इस मुद्दे पर हो गया और तय यह - यह बाहर की कोशिश, रेल डिबगर का उपयोग करें (सिर्फ ऊपर डिबगर लाइन uncomment) बस self.remote_image_url लाइन से पहले कार्यक्रम फ्रीज करने के लिए, तो थोड़ी देर डिबग मोड प्रकार irb में शुरू करने के लिए कंसोल ऊपर। फिर आप प्रिंट कर सकते हैं और वास्तव में क्या देख सकते हैं 'image.direct_fog_url (: with_path => true)' आपको दे रहा है। आप इसे ब्राउज़र में कॉपी और पेस्ट कर सकते हैं। यदि यह गलत है (शायद है) तो आपको मूर्ख अनुमतियां त्रुटि मिल जाएगी (भले ही यह अनुमति समस्या न हो), लेकिन जब यह सही हो तो आप अपलोड की गई छवि देखेंगे या छवि डाउनलोड होगी।

अपने अमेज़ॅन एस 3 कंसोल को खोलने और अपनी देव बाल्टी देखने का अच्छा विचार है ताकि आप अभी अपलोड की गई छवि पा सकें। कंसोल में छवि ढूंढें और इसकी प्रॉपर्टी पर जाएं और आप वेब पता/यूआरएल देख सकते हैं कि आप का उपयोग करने के लिए हैं।

उम्मीद है कि इससे मदद मिलती है। भ्रामक त्रुटि के कारण मेरे लिए ट्रैक करना मुश्किल था, मैंने अपने एस 3 बाल्टी पर अनुमतियों को सही करने की कोशिश करने का एक गुच्छा बिताया लेकिन यह समस्या नहीं थी, सीडब्ल्यूडायरेक्ट जीथब पेज से वह कोड मेरे लिए काम नहीं करता है (मणि संस्करण ??)।

संबंधित मुद्दे