2014-07-16 11 views
5

रेल 4.0.2 में, मैं s3_direct_upload और aws-sdk रत्नों के लिए फ़ाइल अपलोड के लिए सीधे उपयोग कर रहा हूं। विकास के वातावरण में यह ठीक काम कर रहा है, लेकिन उत्पादन वातावरण में यह नीचे की तरह,s3_direct_upload उत्पादन सर्वर में काम नहीं कर रहा है

ActionView::Template::Error (no implicit conversion of nil into String) 

दृश्यों में

<%= s3_uploader_form :callback_url=>create_cv_url, :id=> "s3_uploader", :key=> "cv_uploads/{unique_id}/${filename}", 
    :key_starts_with=> "cv_uploads/", :callback_param=> "cv[direct_upload_url]", :max_file_size=> 1.megabytes, 
    :expiration=> 24.hours.from_now.utc.iso8601 do %> 

    <%= file_field_tag :file, multiple: true, :max_file_size => 1.megabytes, accept: 'application/pdf application/msword application/rtf application/doc application/docx' %> 

<% end %> 

<script id="template-upload" type="text/x-tmpl"> 
<div id="upload_{%=o.unique_id%}" class="upload"> 
    <h5 class="mt1">Please Wait. <span style="color: #5f6fa0;"> {%=o.name%} </span>is processing...</h5> 
    <div class="progress"><div class="progress-bar progress-bar-striped active" style="width: 0%;"></div></div> 
</div> 

यहाँ एक त्रुटि, फेंक रहा है, इस मुद्दे को मुख्य रूप से s3_uploader_form लाइन की ओर इशारा करते है (विचारों में)।

यह सुविधा पूरी तरह से http://blog.littleblimp.com/post/53942611764/direct-uploads-to-s3-with-rails-paperclip-and

में जाना जाता है paperclip.rb

Paperclip::Attachment.default_options.merge!(
url:     :s3_domain_url, 
path:     ':class/:attachment/:id/:style/:filename', 
storage:    :s3, 
s3_credentials:  Rails.configuration.aws, 
s3_permissions:  :private, 
s3_protocol:   'http' 
) 

require 'paperclip/media_type_spoof_detector' 
module Paperclip 
class MediaTypeSpoofDetector 
    def spoofed? 
    false 
    end 
end 
end  

में aws.rb

require 'aws-sdk' 
# Rails.configuration.aws is used by AWS, Paperclip, and S3DirectUpload 
Rails.configuration.aws = YAML.load(ERB.new(File.read("# {Rails.root}/config/aws.yml")).result)[Rails.env].symbolize_keys! 
AWS.config(:logger=> Rails.logger) 
AWS.config(Rails.configuration.aws) 

में s3_direct_upload.rb

S3DirectUpload.config do |c| 
c.access_key_id  = Rails.configuration.aws[:access_key_id] 
c.secret_access_key = Rails.configuration.aws[:secret_access_key] 
c.bucket   = Rails.configuration.aws[:bucket] 
c.region   = "s3" 
end 

मैं में उत्पादन वातावरण में कॉन्फ़िगरेशन समस्या के कारण यह है? कृपया इस मुद्दे को हल करने में मेरी मदद करें।

उत्तर

6

मैं एक ही समस्या थी और मैं इसे अपने S3 पहचान के साथ फ़ाइल config.yml जोड़ने का समाधान:

RailsApp/config.yml

# Fill in your AWS Access Key ID and Secret Access Key 
    # http://aws.amazon.com/security-credentials 
    access_key_id: xxxxxx 
    secret_access_key: xxxxxxx 

और जानकारी: https://docs.aws.amazon.com/AWSSdkDocsRuby/latest/DeveloperGuide/ruby-dg-setup.html

+0

आपके उत्तर के लिए धन्यवाद। Aws.yml फ़ाइल बदलने के बाद यह काम कर रहा है –

2

कोड ठीक लगता है। skozz का उल्लेख किया गया है, एक समस्या आपकी कॉन्फ़िगरेशन कुंजी के साथ हो सकती है जिसे ठीक से असाइन नहीं किया जा सकता है। कृपया "/config/aws.yml" में aws उत्पादन कुंजी जांचें।

0

मैं इस link का पालन करके, वही पीड़ित था। बात यह है कि मैंने प्रारंभकर्ताओं को जोड़ा है, लेकिन मुझे रेलों को पुनरारंभ करने की आवश्यकता है (यह चल रहा था लेकिन ताज़ा नहीं किया गया था)।

0

इस आदेश को निष्पादित करने के लिए मेरे लिए काम किया। figaro heroku:set -e production

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