如何在Heroku上创建永久文件? [英] How to create permanent files on Heroku?

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

问题描述

我在Heroku Free dyno上托管了一个带有Postgres DB的电报机器人.在代码的一个阶段,我想永久保存腌制的文件,以便以后可以访问它们.将其存储在表上并不是一个好主意,因为它是具有可变数量输入的嵌套类. 问题是Heroku经常或至少在每次重新启动或推送时删除这些文件.有什么办法解决这个问题?

I have a telegram bot with a Postgres DB hosted on Heroku Free dyno. In one stage of my code, I want to save pickled files permanently so that I can access them later. Storing it on a table doesn't feel like a nice idea as it is a nested class with a variable number of inputs. Problem is that Heroku deletes these files frequently or at least on each restart or push. Is there any way to tackle this problem?

推荐答案

为此,您必须使用外部服务,例如AWS S3,GCP云存储(桶),Azure Blob存储等.或者,您可以考虑使用诸如 Felix云存储 HDrive ,以便轻松集成.

You have to use external services such as AWS S3, GCP Cloud Storage (Buckets), Azure Blob Storage etc.. for that. Or you may consider using an addon such as Felix Cloud Storage, Cloud Cube, Bucketeer, HDrive for easy integration.

这是文档状态:

Heroku文件系统是短暂的-这意味着对 在dyno运行时,文件系统只会持续运行直到dyno被运行为止. 关闭或重新启动.每个dyno靴子都带有干净的副本 最新部署中的文件系统.这类似于多少 基于容器的系统(例如Docker)可以运行.

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".

这两个事实意味着Heroku上的文件系统不适合 持久存储数据.如果您需要存储数据,我们 建议使用数据库插件,例如Postgres(用于数据)或 专用文件存储服务,例如AWS S3(用于静态文件).如果 您不想在AWS上设置帐户来创建S3存储桶,我们 这里也有用于处理静态存储和处理的插件 资产 https://elements.heroku.com/addons

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

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

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