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

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

问题描述

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

然而,似乎在Heroku上没有永久文件系统,只是一个短暂的一个。这是真的吗?如果是这样的话,我有什么选择来存储照片和其他文件吗?

解决方案

确实如此。 Heroku允许你创建云应用程序,但这些云应用程序不是永久的 - 它们是可以在亚马逊EC2上多次复制的实例(或slugs)(这就是为什么使用Heroku进行缩放非常容易)。如果您要推送一个新版本的应用程序,那么slug将被重新编译,并且您在前一个实例中保存到文件系统的任何文件都将丢失。



您最好的选择(无论是在Heroku还是其他地方)都是将用户提交的照片保存到CDN。由于您使用的是Heroku,而Heroku使用AWS,所以我推荐使用Amazon S3,并选择启用CloudFront。



这不仅因为它适应Heroku的短暂限制,而且还因为CDN速度更快,并将为您的Web应用程序和用户体验提供更好的服务。


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.

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?

解决方案

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.

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.

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天全站免登陆