Alejleva
Alejleva

Reputation: 3

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

    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

 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:

   <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. Thanks.

Upvotes: 0

Views: 1145

Answers (1)

Bart Jedrocha
Bart Jedrocha

Reputation: 11570

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.

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

Upvotes: 4

Related Questions