Cant access image on aws-s3 saved via django

Url of image stored in db is: profile_pictures/f292ddfe-ee17-4ccc-be85-0398fb602753.jpeg

but when i click on it, url becomes https://workandhomes.s3.amazonaws.com/media/profile_pictures/f292ddfe-ee17-4ccc-be85-0398fb602753.jpeg?AWSAccessKeyId={keyHere}&Signature={somevalue}&Expires=1728557943

these is my relevant code:

models.py

class UserProfile(models.Model):

 ...
    profile_picture = models.ImageField(
        upload_to="profile_pictures/", blank=True, null=True
    )

...
    class Meta:
        db_table = "user_profile"

settings.py

....

# AWS S3 Configuration
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME")
AWS_REGION = os.getenv(
    "AWS_REGION", "eu-north-1"
)  # Replace 'your-default-region' with your region

# Configure the default file storage to use S3
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"


MEDIA_URL = f"https://{AWS_STORAGE_BUCKET_NAME}.s3.{AWS_REGION}.amazonaws.com/"

...

I am able to perform the put operations and upload the file, but i cant read it. my IAM user on AWS as fullAccess to aws. and following is the bucket policy

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::workandhomes/*"
        }
    ]
}

Lastly when i remove the auth query strings, image opens.

Any idea what is happening here ?

Вернуться на верх