【发布时间】:2013-12-02 22:05:13
【问题描述】:
我对回形针有疑问。我将其设置为将附件存储在 s3 中,并且我有很多原始大小的附件。问题是我需要重新处理它们以使每个图像具有 3 个不同的尺寸。我在回形针自述文件中读到#reprocess!方法可能有用。
这是我的带有附件的用户类:
has_attached_file :avatar, styles:
{
large: ["135x135#", :jpg],
thumb: ["50x50#", :jpg],
small: ["30x30#", :jpg]
},
default_url: '/placeholders/avatars/:style.png',
url: '/system/users/:attachment/:id_partition/:style/:filename',
storage: :s3,
bucket: ENV['S3_BUCKET'],
s3_credentials: {
:access_key_id => ENV['S3_ACCESS_KEY'],
:secret_access_key => ENV['S3_SECRET_KEY']
}
validates_attachment :avatar,
content_type: {
content_type: /^image\/(jpg|jpeg|pjpeg|png|x-png|gif)$/,
message: 'is not allowed (only images)'
},
size: {
in: 0..1.megabytes,
message: 'is too big'
}
我还在 development.rb 和 production.rb 中将凭据设置为 s3。当我运行重新处理!在每个 user.avatar 对象上,它都返回 true,但文件夹结构不会改变。
pry(#<Importer::Mugshots>)> user.avatar.reprocess!
(0.6ms) BEGIN
(5.3ms) UPDATE "users" SET "avatar_content_type" = '', "avatar_file_size" = 30735, "avatar_updated_at" = '2013-11-19 11:10:17.486960', "avatar_file_name" = '78398594.jpg', "updated_at" = '2013-11-19 11:10:19.001503' WHERE "users"."id" = 542025
(11.6ms) COMMIT
=> true
我尝试更改回形针配置以使用本地文件系统,但没有帮助。可能是什么?
【问题讨论】:
-
日志中是否有类似
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: /dir/file.jpg is not recognized by the 'identify' command.>的内容?这将表明reprocess!失败,因为原始文件在本地不可用,因为它已上传到 S3。
标签: ruby-on-rails amazon-web-services amazon-s3 paperclip