问题
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.
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:
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.
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.
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)
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:
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.
来源:https://stackoverflow.com/questions/4654111/paperclip-w-imagemagick-amazon-s3-and-heroku-imagemagick-s3-work-but-the