Images disappearing in heroku even after storing them in S3 bucket

*爱你&永不变心* 提交于 2020-07-23 08:01:11

问题


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.

In my 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'

In my models.py:

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

    def __str__(self):
        return self.name

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/


回答1:


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.



来源:https://stackoverflow.com/questions/61538225/images-disappearing-in-heroku-even-after-storing-them-in-s3-bucket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!