everytime push to heroku, images is not showed ,paperclip

一世执手 提交于 2019-12-20 09:45:29

问题


here was my situation.

I was using paperclip to let user upload images. It did well and everything was okay. Then,I pushed it to heroku. For the momment, I can see all my images that was just upload by users. However, everytime make a new commit and push to heroku again, all of my previous images gone. It's seems like dont have the file anymore,cant load it.

So,here what i thought: Is it every time i pushed to the heroku server, the images file that was in local was uploaded to the heroku server?

I did research for my problem for it,and im not really understand what they actually said about heroku and i don't know is it is the same problem with me.

Heroku has a read-only filesystem. That means Paperclip cannot save uploaded files to any place within Heroku.

If you would like to be able to upload files to an application hosted on Heroku, then you must either store the files as binary blobs within your database or you must use a separate service to store the files. If you are looking for a separate service, Paperclip has built-in support for integrating with Amazon S3.

I found out that Amazon S3 need credit card to register,if i do not have credit card,then i cannot use their services??

Any detail advices and explaination is appreciated .Thanks you


回答1:


Amazon is not a free device, you must to give your credit-card number to use it. However You pay only what you use but it is not expensive. For example for my websites, last month I paid $2.46 for 15Gb of storage and I paid $1.90 for 16Gb of data transfert.

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

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

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

Then I have a model which store my assets, 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 it helps



来源:https://stackoverflow.com/questions/10425843/everytime-push-to-heroku-images-is-not-showed-paperclip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!