Rails应用程序使用Paperclip和Mongoid上传图片到Amazon S3失败

3
我正在尝试将与“优惠券”对象相关联的图像存储在Amazon S3实例中。我的Rails 3.1应用程序使用Mongoid进行文档存储,并且我正在尝试通过mongoid-paperclip将优惠券的图像存储在Amazon S3上。
我已经在Amazon S3上创建了一个权限组并添加了一个用户;有效的权限已被添加到我的应用程序中(我可以验证,因为如果我删除或更改权限,我会收到错误),但是当我尝试保存文件时,文件的信息存储在数据库中,但文件没有上传。如果我从方程式中删除mongoid-paperclip,文件也不会存储在本地(尽管我确实看到它们存在于我的本地机器上的临时文件夹中,并通过ImageMagick进行处理)。
模型
我的“优惠券”对象嵌入许多“图像”对象,如下所示:
class Coupon
  include Mongoid::Document
  include Mongoid::Timestamps

  # Relationships
  embeds_one :image, as: :imageable

  # Database Schema
  field :name
  field :description
  field :expires, type: Date

  # Validation
  validates :name, :description, :presence => true

end


class Image
  include Mongoid::Document
  include Mongoid::Paperclip
  include Mongoid::Timestamps

  # Relationships
  embedded_in :imageable, polymorphic: true
  has_mongoid_attached_file :file,
    :path           => ':id/:style.:extension',
    :storage        => :s3,
    :s3_credentials => File.join(Rails.root, 'config', 's3.yml'),
    :styles => {
      :original => ['920x920>', :jpg]
    }

end

我在控制台或日志中没有看到来自Paperclip的任何输出,也无法确定如何启用此类输出。与上传文件相关的唯一记录信息如下,在成功更新属性后立即重定向页面之前: | Command :: identify -format %wx%h '/var/folders/ff/vxzlz741287dsr006bv2s59c0000gn/T/stream20111022-80997-o1pqk.png[0]' | Command :: convert '/var/folders/ff/vxzlz741287dsr006bv2s59c0000gn/T/stream20111022-80997-o1pqk.png[0]' -resize "920x920>" '/var/folders/ff/vxzlz741287dsr006bv2s59c0000gn/T/stream20111022-80997-o1pqk20111022-80997-5z9phe.jpg'
2个回答

0
也许,这段代码没有使用回调函数。 Paperclip使用after_save回调来保存图像。
embeds_one :image, as: :imageable, cascade_callbacks: true 

你应该使用 Mongoid 的级联回调。 http://mongoid.org/en/mongoid/docs/callbacks.html

0

这似乎是由于您本地的ImageMagick安装提供的identify命令出现了问题。您的系统上是否安装了ImageMagick的库?我曾经遇到过类似的问题,安装来自brew的ImageMagick似乎解决了它。FYI:我的问题是由于坏的符号链接引起的,identify命令(和其他命令)从我编译ImageMagick源代码时没有正确链接。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接