Amazon S3


When hosting a Django application on a cloud hosting provider, such as Heroku, using Amazon S3 for storing static and media files is often recommended. This is because Heroku's and other provider's filesystems are often not intended for permanent storage and does not support file uploads, and any files uploaded to the filesystem are not preserved.

This is because these files can take up a significant amount of disk space, which can increase server costs and slow down the performance of the application.

Using a cloud storage service also has other benefits, such as easy scalability and accessibility, reliability, and cost-effectiveness. Additionally, using a cloud storage service like Amazon S3 allows for better separation of concerns between the web server and the storage of files.




Remove files from storage when deleting their corresponding models entries:

Inside a model containing a file: add this method:

at the bottom of models.py add:




DJANGO STORAGES (public access to all files)

Install the required packages

pip install django-storages
pip install boto3

Amazon AWS

Create an AWS account

Create a bucket

Permissions

Create credentials

.env - Hide Amazon Keys

Inside .env paste:

AWS_ACCESS_KEY_ID = ' Access Key ID '
AWS_SECRET_ACCESS_KEY=' Secret Access Key '

settings.py

Add the following configuration