Heroku 没有永久文件系统? [英] No permanent filesystem for Heroku?

查看:31
本文介绍了Heroku 没有永久文件系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在 Heroku 上托管的应用允许用户提交照片.最初,我考虑将这些照片存储在文件系统中,因为将它们存储在数据库中显然是不好的做法.

The app I am currently hosting on Heroku allows users to submit photos. Initially, I was thinking about storing those photos on the filesystem, as storing them in the database is apparently bad practice.

然而,Heroku 上似乎没有永久的文件系统,只有一个短暂的文件系统.这是真的吗?如果是,我在存储照片和其他文件方面有哪些选择?

However, it seems there is no permanent filesystem on Heroku, only an ephemeral one. Is this true and, if so, what are my options with regards to storing photos and other files?

推荐答案

确实如此.Heroku 允许您创建云应用程序,但这些云应用程序不是永久性的"——它们是可以在 Amazon EC2 上多次复制的实例(或slugs")(这就是使用 Heroku 可以轻松扩展的原因).如果您要推送应用的新版本,那么 slug 将被重新编译,并且您在前一个实例中保存到文件系统的任何文件都将丢失.

It is true. Heroku allows you to create cloud apps, but those cloud apps are not "permanent" - they are instances (or "slugs") that can be replicated multiple times on Amazon's EC2 (that's why scaling is so easy with Heroku). If you were to push a new version of your app, then the slug will be recompiled, and any files you had saved to the filesystem in the previous instance would be lost.

您最好的选择(无论是在 Heroku 上还是在其他地方)是将用户提交的照片保存到 CDN.由于您使用的是 Heroku,并且 Heroku 使用 AWS,因此我建议使用 Amazon S3,并可选择启用 CloudFront.

Your best bet (whether on Heroku or otherwise) is to save user submitted photos to a CDN. Since you are on Heroku, and Heroku uses AWS, I'd recommend Amazon S3, with optionally enabling CloudFront.

这是有益的,不仅因为它绕过了 Heroku 的短暂限制",还因为 CDN 速度更快,将为您的 Web 应用程序和用户体验提供更好的服务.

This is beneficial not only because it gets around Heroku's ephemeral "limitation", but also because a CDN is much faster, and will provide a better service for your webapp and experience for your users.

这篇关于Heroku 没有永久文件系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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