Paperclip w/ Imagemagick、Amazon S3和Heroku - Imagemagick和S3工作,但是Paperclip字段在数据库中没有设置。在开发

时间:2021-07-15 09:00:14

I'm using Paperclip with Imagemagick in my app, using Amazon S3 for storage. Everything works fine in development. But in production on Heroku it's not working correctly.

我在应用程序中使用Paperclip和Imagemagick,使用Amazon S3存储。在发展中,一切都很好。但是在Heroku的制作中,它并没有正常工作。

The image gets uploaded to Amazon S3, and the thumbnail creation works, so that part of the Paperclip, Imagemagick and S3 combo is working ok. But for some reason, the Paperclip specific model fields are not getting filled:

图像被上传到Amazon S3,缩略图创建工作正常,所以Paperclip、Imagemagick和S3组合的部分工作正常。但是由于某些原因,特定于Paperclip的模型字段没有被填满:

imagestore_file_name: 
imagestore_content_type: 
imagestore_file_size: 
imagestore_updated_at: 

In development, these all get filled in, but not in production on Heroku. When I try to display an image in production app (Heroku), it says that it's missing, even though it is definately there in S3. What could be causing this error? Thanks for reading.

在开发中,这些都被填满了,但在Heroku上没有。当我试图在产品应用程序(Heroku)中显示图像时,它说它丢失了,尽管它确实存在于S3中。是什么导致了这个错误?感谢你的阅读。

Details:

细节:

ruby 1.8.7
Rails 3.0.1
Stack: bamboo-mri-1.9.2

EDIT:

编辑:

Here is the class. The Image class extends Media, which extends ActiveRecord::Base.

这是类。Image类扩展了媒体,它扩展了ActiveRecord: Base。

class Image < Media

  attr_accessor :imagestore_file_name
  attr_accessor :imagestore_content_type
  attr_accessor :imagestore_file_size
  attr_accessor :imagestore_updated_at


    has_attached_file :imagestore, 
        :storage => :s3, 
        :s3_credentials => "#{RAILS_ROOT}/config/amazon_s3.yml", 
        :path => "/:style/:filename",
        :styles => { :medium => "800", :thumb => "150" }


end

Here is the relevant Heroku log (I think, can be hard to tell on Heroku sometimes)

这里有相关的Heroku日志(我认为,有时候很难对Heroku进行区分)

Parameters: {"authenticity_token"=>"a9+UnIlVH5HRetoN45IlGlGYoeEkpqQ1Qskpe4EGuHw=", "media_input"=>"", "imagestore"=>#<File:/home/slugs/44ca6411-6e76-4e7d-8239-a956dc3979c0/mnt/tmp/RackMultipart20110110-17158-10fuv0p>, "type"=>"uber", "name"=>"Star Wars", "detail"=>""}
[paperclip] identify -format %wx%h '/home/slugs/44ca6411-6e76-4e7d-8239-a956dc3979c0/mnt/tmp/stream20110110-17158-1uyk3if.jpg[0]' 2>/dev/null
[paperclip] convert '/home/slugs/44ca6411-6e76-4e7d-8239-a956dc3979c0/mnt/tmp/stream20110110-17158-1uyk3if.jpg[0]' -resize "800" '/home/slugs/44ca6411-6e76-4e7d-8239-a956dc3979c0/mnt/tmp/stream20110110-17158-1uyk3if20110110-17158-ta9egy' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/44ca6411-6e76-4e7d-8239-a956dc3979c0/mnt/tmp/stream20110110-17158-1uyk3if.jpg[0]' 2>/dev/null
[paperclip] convert '/home/slugs/44ca6411-6e76-4e7d-8239-a956dc3979c0/mnt/tmp/stream20110110-17158-1uyk3if.jpg[0]' -resize "150" '/home/slugs/44ca6411-6e76-4e7d-8239-a956dc3979c0/mnt/tmp/stream20110110-17158-1uyk3if20110110-17158-13448fs' 2>/dev/null
[paperclip] Saving attachments.
[paperclip] saving /original/starWarsart2.jpg
[paperclip] saving /medium/starWarsart2.jpg
[paperclip] saving /thumb/starWarsart2.jpg
[paperclip] Saving attachments.
Redirected to !!my site url is here!!
Completed 302 Found in 1029ms

Here are the relevant fields from the Image record that is created:

以下是创建的图像记录中的相关字段:

  imagestore_file_name: 
  imagestore_content_type: 
  imagestore_file_size: 
  imagestore_updated_at:

In development, these fields have data and I am able to load the images. But not in production. Thanks for your help.

在开发中,这些字段具有数据,我可以加载图像。但不是在生产。谢谢你的帮助。

1 个解决方案

#1


4  

I think the problem is that you have specified attr_accessor for the paperclip attributes. That is not needed. I actually got the same problem as you when I added those lines to my model. So it should be enough to remove those lines.

我认为问题是您已经为paperclip属性指定了attr_accessor。这并不是必要的。当我把这些线加到我的模型里时,我得到了和你们一样的问题。所以把这些线去掉就足够了。

#1


4  

I think the problem is that you have specified attr_accessor for the paperclip attributes. That is not needed. I actually got the same problem as you when I added those lines to my model. So it should be enough to remove those lines.

我认为问题是您已经为paperclip属性指定了attr_accessor。这并不是必要的。当我把这些线加到我的模型里时,我得到了和你们一样的问题。所以把这些线去掉就足够了。