简体   繁体   English

S3回形针导轨无法显示图像

[英]S3 Paperclip rails Can not display image

I can upload pictures to the bucket fine but can't get them to display on my view 我可以将照片上传到存储桶中,但不能在我的视图中显示它们

Article.rb Article.rb

    class Article < ActiveRecord::Base
  has_attached_file :image,

  :storage => :s3, 
  :bucket => "poles",
  :s3_host_name => 's3.amazonaws.com', 
  :url =>':s3_domain_url',
  :path => '/:class/:attachment/:id_partition/:style/:filename',
  :s3_credentials => {
    :bucket => ENV['AWS_BUCKET'],
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
  }

  validates_attachment :image,
  :content_type => { :content_type => ["image/jpeg", "image/gif", "image/png"] }

end

The view 风景

  <div id="thumbs">
                               <% @article.each do |article| %>

                  <div class="thumb">
                    <div class="frame"><%= image_tag article.image.url %></div>

                    <div class="thumb-content"><p><%= link_to article.title, news_path(article) %></p>Ici txt</div>
                     <div style="clear:both;"></div>
                 </div>


              <% end %>

Dev/Pro.rb 开发/ Pro.rb

 config.paperclip_defaults = {
  :storage => :s3,
  :s3_host_name => 's3.amazonaws.com', 
  :url =>':s3_domain_url',
  :path => '/:class/:attachment/:id_partition/:style/:filename',
  :s3_credentials => {
    :bucket => ENV['AWS_BUCKET'],
    :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
    }
}

The link of the image: http://poles.s3.amazonaws.com/articles/images/000/000/007/original/Ruby.png%3F1417027081 And it's error with S3: 图片的链接: http : //poles.s3.amazonaws.com/articles/images/000/000/007/original/Ruby.png%3F1417027081这是S3的错误:

   <Error><Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>articles/images/000/000/007/original/Ruby.png?1417027081</Key><RequestId>804A29415B8B2A8F</RequestId><HostId>BV9jm5FsvkurUvabxSkC+D3tw4Sr+++iwUPpQfB3kTBIuEFaDJeMZmbIzeB9gaHZ+iXWL7cM9us=</HostId></Error>

If i get rid of the ?1417027081 it works but I don't want to do it manually on all the pictures. 如果我删除了?1417027081它可以工作,但我不想在所有图片上手动进行。 Thanks. 谢谢。

Your issue is related to a recent commit which doesn't properly escape the timestamp. 您的问题与最近提交有关,该提交无法正确逃避时间戳。 A temporary workaround is to disable the timestamp while a fix is worked-out. 临时的解决方法是在解决问题时禁用时间戳。

<%= image_tag article.image.url(:original, timestamp:false) # or whatever style you're using %>

Or you can disable this globally by putting the following line within your config/initializers/paperclip.rb file . 或者,您可以通过将以下行放在config/initializers/paperclip.rb file全局禁用此功能。

Paperclip::Attachment.default_options[:use_timestamp] = false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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