How to configure django 5.0.3 to be able to use private/public media files on AWS - s3

19 Views Asked by At

today I feel very frustrated , after 3 days trying to implement django using amazon s3 with media file in private mode.

In the past my apps has been configured using the following link bellow and always work fine:

https://unfoldadmin.com/blog/configuring-django-storages-s3/

From now for some reasson is not possible to reach the goald (some media files need to be private) I undestand that from django 4.2 exist new way to configure storages but still you are able to continue with old option, To be honest I do not sure if this will be the cause of the problem:

https://docs.djangoproject.com/en/5.0/ref/settings/

{
    "default": {
        "BACKEND": "django.core.files.storage.FileSystemStorage",
    },
    "staticfiles": {
        "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
    },
}
versions:
Phyhon: 3.12.2
asgiref==3.8.1
boto3==1.34.72
botocore==1.34.72
Django==5.0.3
django-storages==1.14.2
jmespath==1.0.1
python-dateutil==2.9.0.post0
s3transfer==0.10.1
six==1.16.0
sqlparse==0.4.4
tzdata==2024.1
urllib3==2.2.1

Configuration on AWS:
Object Ownsership:ACls enabled
Block all public access: off

Bucket policy: 
{
    "Version": "2012-10-17",
    "Id": "Policy_id",
    "Statement": [
        {
            "Sid": "my_sid",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mybucket_name/*"
        }
    ]
}

Note: I have to say that appear the ACLs is working because after uploading a private file if you try to retrieve the URL of the content , the API will generate a long URL that expire after a few minutes, however in order to test, I just try to access the file directly, without the parameters but I never get the standart AWS error message.

I really apreciate your support.

I expected that only the user authenticated can access the private files.

0

There are 0 best solutions below