Sushang Agnihotri
Sushang Agnihotri

Reputation: 666

how to uplaod image in django rest framework with heroku and aws s3 bucket storage

i am using heroku for my django rest framework project and i am using whitenoise storage but the problem with this is that after image uploading image it is disappear after some time

i want permanently image storage with aws s3 bucket help me with that

models.py

class UploadImage(models.Model):
    img_id = models.AutoField(primary_key=True)
    image = models.ImageField(upload_to='media/images/')

    def __str__(self):
        return str(self.image)

what changes i have to make to use and store the images in aws s3 bucket

Upvotes: 0

Views: 156

Answers (1)

Sushang Agnihotri
Sushang Agnihotri

Reputation: 666

requirements.txt

boto3==1.17.8
django-storages==1.11.1

or you can download using

pip install boto3
pip install django-storages

settings.py

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

AWS_ACCESS_KEY_ID = 'YOUR_AWS_ACCESS_KEY_ID'
AWS_SECRET_ACCESS_KEY = 'YOUR_AWS_SECRET_ACCESS_KEY'
AWS_STORAGE_BUCKET_NAME = 'YOUR_AWS_STORAGE_BUCKET_NAME'
AWS_QUERYSTRING_AUTH = False

apply this changes and you will good to go

Upvotes: 1

Related Questions