Each time click on the hero, images are not shown, clip

here is my situation.

I used paperclip to allow users to upload images. Everything went well and everything was in order. Then I pushed him to the hero. For momment, I can see all my images that were simply uploaded by users. However, each time make a new commit and click on the hero again, all my previous images have disappeared. It seems that you no longer have the file, I can’t upload it.

So here is what I thought: Is this every time I click on the heroku server, the image file that was in local was uploaded to the heroku server?

I was researching my problem, and I really don’t understand what they were really talking about the hero, and I don’t know that this is the same problem with me.

Heroku has a read-only file system. This means that Paperclip cannot save downloaded files anywhere in Heroku.

If you want to upload files to an application hosted on Heroku, you must either store the files as binary drops in your database, or you must use a separate service to store the files. If you're looking for a standalone service, Paperclip has built-in integration support with Amazon S3.

I found out that Amazon S3 needs a credit card to register, if I do not have a credit card, then I can not use their services?

Any detailed tips and explanations are welcome. Thanks you,

+7
source share
1 answer

Amazon is not a free device; you must provide your credit card number in order to use it. However, you only pay for what you use, but it is not expensive. For example, for my websites last month I paid $ 2.46 for 15 GB of memory, and I paid $ 1.90 for 16 GB of data transfer.

To use S3 with paperclip, you need to add gem 'aws-s3' to the Gemfile

Then you need to add config/s3.yml credentials of your assets, for example:

 production: access_key_id: AAAAAAAAAAAAAAAAAA secret_access_key: BBBBBBBBBBBBBBBBBBBBBBBBBBB bucket: assets.my-bucket 

Then I have a model in which my assets are stored, for example:

 class Asset has_attached_file :asset, :styles => { :thumb => "60x60#", :large => "700x330#"}, :storage => :s3, :s3_credentials => "#{Rails.root}/config/s3.yml", :path => "/images/:id/:style.:extension" validates_attachment_content_type :asset, :content_type => ['image/gif', 'image/jpeg', 'image/png', 'image/x-ms-bmp'] end 

I hope this helps

+5
source

All Articles