回形针不会在 Heroku 上创建缩略图

发布于 2024-10-03 08:49:20 字数 1041 浏览 3 评论 0原文

我一直在尝试使用回形针将图像上传到亚马逊 s3,但我得到的只是正在上传的原始文件。不生成缩略图。我的模型中有这样的内容:

  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"

原始文件实际上已上传,但没有出现缩略图。例如,如果我复制拇指格式图像的 src,我会得到

<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>screenshots/8/thumb.png</Key>
<RequestId>B8A408560070E836</RequestId>
−
<HostId>
HAHUCuNxGKVDvqE3GnhGT1RcBgFGUxa35kqXmyRE+ii60DJS6r22ChDr22cOeCea
</HostId>
</Error>

This is running on heroku,这迫使我使用像亚马逊这样的服务。不是问题,但我能找到的所有文档都使这看起来很简单。我找不到任何依赖项(bundler 很高兴),而且我已经使用 AWS 两年了,没有出现这些问题,在另一个站点上,同一帐户上有不同的存储桶。是不是账号连接桶的问题?我使用与其他站点相同的凭据。只有桶发生变化。

还有一些事情。在正在上传的图像的路径中创建的目录的权限为 000 或任何 aws 等效权限。任何人都不被允许做任何事。

使用 Rails 3。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌若浮生 2024-10-10 08:49:20

我有同样的问题,答案在于:

:路径=> “:附件/:id/:样式.:扩展名”

不要将图像存储在具有不同名称的同一folder_id 中,而是使用相同的图像名称并使用文件夹的样式。上面的内容可以翻译成:

:路径=> “:附件/:id/:样式/:文件名”

因此,您不必尝试生成类似以下内容:

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

您会得到以下结果:

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

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
葬花如无物 2024-10-10 08:49:20

我安装了回形针作为插件,一切正常。

不要忘记从 Gemfile 中删除 gem。

I installed paperclip as a plugin, and everything works.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文