繁体   English   中英

回形针image_tag不显示带有S3和Rails的图像

[英]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 %>

更新:解决方案

要使其工作,需要做两件事:

  1. s3_host_name: "s3-#{ENV['AWS_REGION']}.amazonaws.com"到配置中。 这是此处建议的解决方法。
  2. :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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM