简体   繁体   English

Rails App无法使用Paperclip和Mongoid将图像上传到Amazon S3

[英]Rails App Failing to Save Image Uploads to Amazon S3 Using Paperclip and Mongoid

I'm trying to store images associated with a Coupon object in an Amazon S3 instance. 我正在尝试将与Coupon对象关联的图像存储在Amazon S3实例中。 My Rails 3.1 application uses Mongoid for document storage, and I'm not attempting to introduce Paperclip (via mongoid-paperclip) to store images for coupons on Amazon S3. 我的Rails 3.1应用程序使用Mongoid进行文档存储,我并不是要尝试使用Paperclip(通过mongoid-paperclip)来存储Amazon S3上的优惠券图像。

I've created a permission group on Amazon S3 and added a user; 我在Amazon S3上创建了一个权限组并添加了一个用户; the valid permissions have been added to my application (which I can verify, because if I remove or alter the permissions, I receive an error), but when I attempt to save a file, the file's information is stored in the database, but the file is not uploaded. 有效的权限已添加到我的应用程序(我可以验证,因为如果我删除或更改权限,我收到错误),但当我尝试保存文件时,文件的信息存储在数据库中,但是文件未上传。 If I remove mongoid-paperclip from the equation, files are not stored locally either (although I do see that they exist in a temp folder on my local machine and are processed via ImageMagick). 如果我从等式中删除mongoid-paperclip,文件也不会存储在本地(虽然我确实看到它们存在于我本地计算机上的临时文件夹中并通过ImageMagick处理)。


Models 楷模

My Coupon objects embeds many Image objects as such: 我的Coupon对象嵌入了许多Image对象:

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

I do not see any output from Paperclip in my console or logs and cannot determine how to enable such output. 我在控制台或日志中看不到Paperclip的任何输出,也无法确定如何启用此类输出。 The only information logged in relation to the file being uploaded is as follows, immediately before the page is redirected after successfully updating attributes: 记录与上传文件相关的唯一信息如下,在成功更新属性后重定向页面之前:

| 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'

This seems to be a problem with the identify command provided by your local ImageMagick install. 这似乎是本地ImageMagick安装提供的identify命令的问题。 Do you have ImageMagick's libraries installed on your system? 您的系统上是否安装了ImageMagick库? I had a similar problem once and it seems that installing ImageMagick from brew fixed it up. 我有一个类似的问题,似乎从brew安装ImageMagick修复它。 FYI: My problem was caused by bad symbolic links, the identify command (and others) simply weren't linked correctly from when I compiled ImageMagick from source. 仅供参考:我的问题是由错误的符号链接引起的,当我从源代码编译ImageMagick时,识别命令(和其他)根本没有正确链接。

Maybe, This code is not using callbacks. 也许,这段代码没有使用回调。 Paperclip use the callback of after_save to save a image. Paperclip使用after_save的回调来保存图像。

embeds_one :image, as: :imageable, cascade_callbacks: true 

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM