每次推的Heroku,图像不显示,回形针回形针、图像、Heroku

2023-09-11 08:55:32 作者:幸福伴我身

下面是我的情况。

我是用曲别针,让用户上传照片。它做得很好,一切都还好。然后,我把它的Heroku。对于momment,我可以看到我所有的只是上传用户的图像。然而,每次作出新的承诺,并推到Heroku上再次,所有的走了我的previous图像。它似乎是不必须的文件了,斜面加载它。

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.

所以,在这里我的想法: 是不是每次我推到了Heroku的服务器,这在当地被上传到Heroku的服务器中的映像文件?

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?

我做研究我为它的问题,我不是真正理解他们居然说,大约Heroku和我不知道这是同样的问题与我的。

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的具有一个只读文件系统。这意味着回形针不能上传文件保存到内Heroku的任何地方。

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

如果您希望能够将文件上传到托管在Heroku上的应用程序,那么您必须将文件存储为二进制的blob您的数据库中,或者您必须使用一个单独的服务来存储文件。如果你正在寻找一个单独的服务,回形针有内置的支持与Amazon S3集成。

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.

我发现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??

任何详细建议和的解释是pciated .Thanks你AP $ P $

Any detail advices and explaination is appreciated .Thanks you

推荐答案

亚马逊是不是免费的设备,你必须给你的信用卡号码使用它。但是付您自己要使用的,但它也不是很贵。例如,对于我的网站,我上个月支付了$ 2.46,用于存储15GB和我付出的数据transfert的$ 1.90 16GB。

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.

要使用S3与曲别针,你需要添加宝石AWS-S3的Gemfile

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

接下来,您需要添加配置/ s3.yml 您的资产凭证,例如:

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