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

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

问题描述

我昨天部署了我的第一个 Heroku 应用,一切都运行良好.

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

在我的应用程序中,您可以上传图片,我做到了并且可以在show"上看到它页.然而,今天这个形象消失了.其他一切似乎都很好.该应用程序在我的本地机器和 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

如果您使用回形针或carrierwave 之类的任何宝石进行上传,使用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天全站免登陆