Django.fun

How to create a persigned url for a private s3 bucket using django rest framework

models.py


def upload_org_logo(instance, filename):
    ts = calendar.timegm(time.gmtime())
    filepath = f"Timesheet/org_logo/{ts}"
    if instance:
        base, extension = os.path.splitext(filename.lower())
        filepath = f"Timesheet/org_logo/{instance.org_id}/{instance.org_name}{extension}"
    return filepath

class Organisation(models.Model):
    """
    Organisation model
    """
    org_id = models.CharField(max_length=50,default=uuid.uuid4, editable=False, unique=True, primary_key=True)
    org_name = models.CharField(unique=True,max_length=100)
    org_code = models.CharField(unique=True,max_length=20)
    org_mail_id = models.EmailField(max_length=100)
    org_phone_number = models.CharField(max_length=20)
    org_address = models.JSONField(max_length=500, null=True)
    product = models.ManyToManyField(Product, related_name='products')
    org_logo = models.ImageField(upload_to=upload_org_logo, null=True, blank=True,)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

I am saving the Org_logo in the private s3 bucket, I need to get the Image from the s3 bucket using a presigned url. I checked out some solutions but I am not sure how to use it specifically on where like in models or views or other?

Can you please help me with how to use it and where to use based on my above code.

AWS Settings.py

AWS_ACCESS_KEY_ID = ''
AWS_SECRET_ACCESS_KEY = ''
AWS_STORAGE_BUCKET_NAME = ''
AWS_QUERYSTRING_AUTH = True

AWS_S3_FILE_OVERWRITE = True



AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400',
}

AWS_S3_SIGNATURE_VERSION = 's3v4'
AWS_S3_REGION_NAME = ''
AWS_DEFAULT_ACL = None
AWS_S3_VERIFY = True
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'