S3直接上传不上传文件

时间:2016-01-04 14:23:21

标签: ruby-on-rails ruby heroku amazon-s3 paperclip

/config/intilializers/paperclip.rb

Paperclip::Attachment.default_options[:storage] = :s3
Paperclip::Attachment.default_options[:bucket] = 'xxx'
Paperclip::Attachment.default_options[:s3_permissions] = :public_read
Paperclip::Attachment.default_options[:s3_credentials] = { access_key_id: 'xxx' ,secret_access_key: 'xxx'}

/config/intilializers/s3_direct_upload.rb

S3DirectUpload.config do |c|
c.access_key_id = 'xx'       # your access key id
c.secret_access_key = 'xxx'   
c.bucket = 'xxx'              # your bucket name
c.region = 's3-ap-southeast-1'            
end

AWS.config({
:access_key_id => 'xxx',
 :secret_access_key => 'xxx',
:region => 'ap-southeast-1'
})

Ad.rb

has_attached_file :thumbnail, styles: { thumb: "50x50>" }
validates_attachment_size :thumbnail, :less_than => 100.megabytes
# validates_attachment_presence :thumbnail
validates_attachment_content_type :thumbnail, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]

_form.html.erb

<div class="col-lg-12">                  
        <%= s3_uploader_form callback_url: ads_url,
          id: "s3_uploader",
          callback_param: "ad[thumbnail_url]",
          expiration: 24.hours.from_now.utc.iso8601,
          max_file_size: 100.megabytes do %>
          <%= file_field_tag :file, multiple: true %>
        <% end %>
        <div id="uploads_container"></div>
        <script id="template-upload" type="text/x-tmpl">
        <div id="upload_{%=o.unique_id%}" class="upload">
          <h5>{%=o.name%}</h5>
          <div class="progress progress-striped active"><div class="bar" style="width: 0%"></div></div>
        </div>
        </script>

      </div>

当我提交时,它不会在S3上传任何内容。我错过了什么?

0 个答案:

没有答案