即使将图像存储在S3存储桶中,图像也会在heroku中消失 [英] Images disappearing in heroku even after storing them in S3 bucket

查看:83
本文介绍了即使将图像存储在S3存储桶中,图像也会在heroku中消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 sqlite3 作为我的数据库,即Django默认数据库.有人告诉我Heroku是短暂的.因此,存储的图像将被蒸发.因此,我使用了 Amazon S3存储桶来存储我的所有静态文件以及通过 django管理员上传的图像. 几个小时后,我通过 django管理员上传的图像仍然消失了.

I'm using sqlite3 as my database, i.e., the django default database. I am told Heroku is ephemeral. So the images stored will be vaporized. So I used Amazon S3 bucket for storing all my static files and the images uploaded via django admin. Still the images that I upload via django admin gets disappeared after couple of hours.

在我的 settings.py 中:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

AWS_ACCESS_KEY_ID = **
AWS_SECRET_ACCESS_KEY = **
AWS_STORAGE_BUCKET_NAME = 'bucket'
AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

在我的 models.py 中:

class Moment(models.Model):
    name = models.CharField(max_length=25)
    img = models.ImageField(upload_to='moments')

    def __str__(self):
        return self.name

我需要连接到heroku提供的 Postgresql 吗?或到目前为止,我有没有犯过大错?链接到我的网站: http://fine-arts-club.herokuapp.com/

Do I need to connect to the Postgresql that heroku provides? Or did I make any blunder thus far? The link to my site: http://fine-arts-club.herokuapp.com/

推荐答案

您的SQLite数据库存储在哪里?如果在Dyno上也是如此,则每次Dyno重新启动时,它也会被重置".相反,使用Heroku Postgres将确保您的数据库在重新启动Dyno时仍然有效.

Where is your SQLite database stored? If this is on the Dyno as well, then this will be getting 'reset' each Time the Dyno restarts as well. Using Heroku Postgres instead will ensure your database survives when the Dyno is restarted.

这篇关于即使将图像存储在S3存储桶中,图像也会在heroku中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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