0
在生產和開發中,似乎無法讓AWS-S3與我的Ruby應用程序一起工作。我可以將文件上傳到我的S3 Bucket中,但是如何顯示它們?我正在使用這個用戶配置文件頭像,以便用戶可以上傳他們自己的頭像。使用Paperclip在Ruby應用程序上顯示AWS S3圖像
這裏是我當前的圖像標籤:
<%= image_tag @user.profile.avatar.url, class: 'user-show-avatar' %>
我有我的地方頭像上傳的配置文件模式,即在那裏我有形象信息的信息。
profile.rb
class Profile < ActiveRecord::Base
belongs_to :user
has_attached_file :avatar,
:styles => { :medium => "460x>", :thumb => "100x100>",:vnice=> "400x" },
:storage => :s3,
:bucket => 'mybucket',
:s3_credentials => "#{Rails.root}/config/aws.yml",
:path => "resources/:id/:style/:basename.:extension"
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
end
_form.html.erb(編輯配置文件形式)
<%= form_for @profile, url: user_profile_path, :html => { :multipart => true } do |f| %>
<div class="form-group">
<%= f.label :avatar %>
<%= f.file_field :avatar, class: 'form-control' %>
</div>
<% end %>
配置/初始化/ paperclip.rb
Paperclip::Attachment.default_options[:storage] = :s3
Paperclip::Attachment.default_options[:s3_credentials] = {
:bucket => ENV['AWS_BUCKET'],
:access_key_id => ENV['AWS_KEY'],
:secret_access_key => ENV['AWS_SECRET_KEY'],
s3_region: 'us-east-1'
}
Paperclip::Attachment.default_options[:s3_options] = {
endpoint: 'https://objects-us-east-1.io'
}
Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
Paperclip::Attachment.default_options[:s3_host_name] = 'objects-us-east-1'
Paperclip::Attachment.default_options[:s3_protocol] = 'https'
我在做什麼錯?使用回形針從S3中顯示圖像的正確方法是什麼?