[英]Paperclip image_tag does not show image with S3 and Rails
我在Rails(4.2)應用程序中使用Paperclip進行S3圖像上傳。 一切正常,除了image_tag不顯示圖像而是圖像標題。 我想念什么?
recipe.rb
class Recipe < ActiveRecord::Base
has_attached_file :image, styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
}
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
validates_with AttachmentSizeValidator, attributes: :image, less_than: 1.megabytes
end
食譜show.html.erb
<p id="notice"><%= notice %></p>
<p>
<strong>Name:</strong>
<%= @recipe.name %>
</p>
<div class="col-xs-12" style="height:400px">
<%= image_tag @recipe.image.url(:original) %>
</div>
<%= link_to 'Edit', edit_recipe_path(@recipe) %> |
<%= link_to 'Back', recipes_path %>
更新:解決方案
要使其工作,需要做兩件事:
- 將
s3_host_name: "s3-#{ENV['AWS_REGION']}.amazonaws.com"
到配置中。 這是此處建議的解決方法。- 將
:s3_protocol => :https
添加到配置中,因為aws-sdk-2明確需要此功能(如注釋中所述)。
在aws-adk-2中,您需要在配置中顯式指定s3協議:s3_protocol =>:https。
回形針的最新版本取決於aws-sdk-2。 因此您必須指定協議。
這樣,這將使用https保存您的圖像URL。
這將幫助您查看鏈接 。 你有同樣的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.