为什么上传的图片在Heroku上消失了? [英] Why do uploaded pictures disappear on Heroku?

查看:93
本文介绍了为什么上传的图片在Heroku上消失了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我昨天部署了我的第一个Heroku应用程序,并且一切正常.

I deployed my first Heroku app yesterday, and everything worked great.

在我的应用程序中,您可以上传图像,并且可以在显示"窗口中看到它.页.但是,今天图像消失了.其他一切似乎都正常.除了不存在的映像外,该应用程序在我的本地计算机以及Heroku上都可以正常运行.

In my app you can upload an image, I did and could see it on the "show" page. However, today the image disappeared. Everything else seems to work just fine. The application is working just fine on my local machine as well as on Heroku, other than the image which is not there.

可能是什么问题?我如何确保它不会再次发生?

What may be the problem? How can I make sure it doesn't happen again?

推荐答案

Heroku不支持文件上传.文件系统是只读的.你会 必须将您上传的文件托管在其他位置(或从数据库托管,这是一个糟糕的选择).

Heroku does not support file uploads. The filesystem is readonly. You'll have to host your uploaded files somewhere else (or from the database, which is a bad option).

https://devcenter.heroku.com/articles/read-only-filesystem

Amazon S3是常见的选择: http://devcenter.heroku.com/articles/s3

Amazon S3 is a common choice: http://devcenter.heroku.com/articles/s3

如果您使用回形针或载波等任何宝石进行上传,则使用S3会很简单.您将必须在配置文件中设置S3凭据,gem将负责上传并提供已上传文件的url.

If you are using any gems like paperclip or carrierwave for uploading, using S3 will be simple. You will have to set the S3 credentials in a config file and the gem will take care of uploading and will provide urls for the uploaded file.

这篇关于为什么上传的图片在Heroku上消失了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆