开发者

paperclip doesn't create thumbnails on heroku

I've been trying to get paperclip to upload images to amazon s3, but all I get is the original file being uploaded. No thumbnails are generated. My model has this in it:

  has_attached_file :screenshot, :styles => {
    :thumb => "100x80>",
    :medium => "195x150>",
    :large => "390x300>"
  },
  :storage => :s3,
  :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
  :path => ":attachment/:id/:style.:extension"

The original file is in fact uploaded, but none of thumbnails appear. If I copy the src of a thumb format image, for instance, I get

<Error>
<Code>NoSuchKey</Code>
<Message>The spec开发者_StackOverflow社区ified key does not exist.</Message>
<Key>screenshots/8/thumb.png</Key>
<RequestId>B8A408560070E836</RequestId>
−
<HostId>
HAHUCuNxGKVDvqE3GnhGT1RcBgFGUxa35kqXmyRE+ii60DJS6r22ChDr22cOeCea
</HostId>
</Error>

This is running on heroku, which forces me to use a service like amazon. Not a problem but all the documentation I can find makes this look straightforward. I can't find any dependencies (bundler is happy), and I've been using AWS for 2 years now, without these problems, on another site, with a different bucket on the same account. Is it a problem of connecting the bucket to the account? I'm using the same credentials as in the other site. Only the bucket changes.

A couple more things. The directories that are being created in the path of the image that is being uploaded are permissions 000 or whatever the aws equivalent is. Nobody is permitted to do anything.

using Rails 3.


I had the same problem and the answer lies in:

:path => ":attachment/:id/:style.:extension"

Instead of storing the images in the same folder_id with different names, use the same name for the image and use the style for folders. The above would translate into:

:path => ":attachment/:id/:style/:filename"

So instead of trying to generate something like:

avatars/13/thumb.png
avatars/13/medium.png
avatars/13/large.png

You get this:

avatars/13/thumb/my_pic.png
avatars/13/medium/my_pic.png
avatars/13/large/my_pic.png


I installed paperclip as a plugin, and everything works.

Don't forget to remove the gem from your Gemfile.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜