我可以在Heroku上承载的图片?或者我需要S3?图片、Heroku

2023-09-11 09:28:18 作者:爱悄然离线

我在我的部署web应用程序(它是为企业客户)。因此,用户不会添加图像,但只有企业将。

I'm deploying my web app (it's for a corporate client). So, users will not add images, but only the business will.

我已经部署到Heroku的,和我的图片依然呈现。什么时候需要使用S3?生病有像共100幅图像的网站,和大小会有所不同一样> 7一个星期。我只能使用Heroku的?

I've deployed to Heroku, and my images are still showing. When do I need to use S3? Ill have like 100 images in total in the site, and size will vary like > 7 a week. Can I use only heroku?

推荐答案

简短的回答:如果你允许用户或管理员上传图片,你不应该使用Heroku的文件系统,这是图像会突然消失。

The short answer: if you allow users or admins to upload images, you should not use Heroku's file system for this as the images will suddenly vanish.

由于在 Heroku的文档解释说:

每个赛道都有自己的短暂的文件系统,与最近部署的code一个新的副本。在测功机的生命周期及其运行的进程可以使用文件系统作为临时暂存器,但没有被写入的文件是可见的其他任何赛道流程和书面将被丢弃到了极致停止或重新启动的那一刻的任何文件。

Each dyno gets its own ephemeral filesystem, with a fresh copy of the most recently deployed code. During the dyno’s lifetime its running processes can use the filesystem as a temporary scratchpad, but no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted.

这意味着,用户上传到Heroku的文件系统映像,不仅消灭了每推,而且还与每一个赛道重启,偶尔发生的(即使你会经常ping通他们prevent他们睡觉) 。

This means that user uploaded images on the Heroku filesystem are not only wiped out with every push, but also with every dyno restart, which occasionally happens (even if you would ping them frequently to prevent them going to sleep).

一旦你开始使用第二个网络赛道,这将无法读取其他赛道的文件系统,这样的话图像就只能被从一个赛道。这将导致奇怪的问题,用户可以在这里有时会看到图像,有时他们不这样做。

Once you start using a second web dyno, it will not be able to read the other dyno's filesystem, so then images would only be visible from one dyno. This would cause weird issues where users can sometimes see images and sometimes they don't.

这是说,你可以暂时存储在Heroku的文件系统映像如果实现一个直通文件上传到外部文件存储。

That said, you can temporarily store images on the Heroku filesystem if you implement a pass-through file upload to an external file store.