2014-07-16 27 views
5

Trong Rails 4.0.2, tôi đang sử dụng trực tiếp s3_direct_uploadaws-sdk đá quý để tải tệp lên cho gói s3. Trong môi trường phát triển nó đang làm việc tốt nhưng trong môi trường sản xuất nó được ném một lỗi như dưới đây,s3_direct_upload không hoạt động trong máy chủ sản xuất

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

trong quan điểm,

<%= 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> 

Ở đây, vấn đề này chủ yếu chỉ vào s3_uploader_form dòng (trong chế độ xem).

Tính năng này là hoàn toàn gọi từ http://blog.littleblimp.com/post/53942611764/direct-uploads-to-s3-with-rails-paperclip-and

Trong 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  

Trong 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) 

Trong 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 

tôi vì vấn đề cấu hình trong môi trường sản xuất? Làm ơn giúp tôi giải quyết vấn đề này.

Trả lời

6

tôi đã cùng một vấn đề và tôi giải quyết nó bổ sung thêm file config.yml với các thông tin S3 của tôi:

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 

Thông tin thêm: https://docs.aws.amazon.com/AWSSdkDocsRuby/latest/DeveloperGuide/ruby-dg-setup.html

+0

Cảm ơn câu trả lời của bạn. Làm việc của nó sau khi thay đổi tập tin aws.yml –

2

Mã có vẻ ok. Như skozz đã đề cập, một trong những vấn đề có thể là do các khóa cấu hình có thể không được gán đúng cách. Vui lòng kiểm tra các khóa sản xuất aws trong "/config/aws.yml".

0

Tôi đã bị giống nhau, bằng cách làm theo điều này link. Vấn đề là tôi đã thêm initializers, nhưng tôi cần phải khởi động lại đường ray (nó đang chạy nhưng không được làm mới).

0

Thực hiện lệnh này đã hoạt động đối với tôi. figaro heroku:set -e production

Các vấn đề liên quan