简体   繁体   中英

Paperclip image_tag does not show image with S3 and Rails

I am using Paperclip for S3 image uploading in my Rails (4.2) app. Everything works fine, except of the fact that the image_tag does not show the image but the title of the image. What am I missing?

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

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

UPDATE: Solution

Two things are needed to make it work:

  1. Add s3_host_name: "s3-#{ENV['AWS_REGION']}.amazonaws.com" to config. This is a workaround as suggested here .
  2. Add :s3_protocol => :https to config as aws-sdk-2 needs this explicitly (as mentioned in the comments).

In aws-adk-2 you need to specify s3 protocol explicitly in your configuration :s3_protocol => :https.

latest versions of paperclip depend on aws-sdk-2. so you have to specify the protocol.

In this way this way this will save your image URL with https.

This answe will help you see the link . you have the same problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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