无法加载用户在 heroku 上使用 arc on prod 上传的图像

Can't load images users uploaded with arc on prod on heroku

我使用 arc 来保存用户上传并添加到数据库。在本地主机上一切正常(在 lib/app_web/endpoint.ex

plug Plug.Static,
    at: "/uploads", from: Path.expand("./uploads"), gzip: false

我不明白我可以在 heroku 上的什么地方保存上传,所以我可以使用 https://app.herokuapp.com/uploads/images/...

访问它们

将文件直接上传到 Heroku 的问题是,每次您的 dyno stops/restarts 时,它们都会被删除。因此,您需要将这些文件存储在 Heroku 应用程序之外。一种解决方案是使用 AWS S3(如果您没有大量数据,它非常便宜,如果您存储 20 GB 并有 100GB 流量,则每月半美元)。

来自Heroku help pages

The Heroku filesystem is ephemeral - that means that any changes to the filesystem whilst the dyno is running only last until that dyno is shut down or restarted. Each dyno boots with a clean copy of the filesystem from the most recent deploy. This is similar to how many container based systems, such as Docker, operate.

In addition, under normal operations dynos will restart every day in a process known as "Cycling".

These two facts mean that the filesystem on Heroku is not suitable for persistent storage of data. In cases where you need to store data we recommend using a database addon such as Postgres (for data) or a dedicated file storage service such as AWS S3 (for static files). If you don't want to set up an account with AWS to create an S3 bucket we also have addons here that handle storage and processing of static assets https://elements.heroku.com/addons