we am using django rest framework for a project and here we are trying to avoid using serializers. We have our AWS S3 as private , hence we need to provide a presigned key for the user to be able to see the image . Initially , we had our S3 as public so we were using annotate function to convert the image path to image link like this :
def getImageFormatter(key:str)->Func:
"""Function to Get Formatted URL"""
return Case(
When(
**{f'{key}__exact':''},
then=Value(None)
),
When(
**{f'{key}__isnull':False},
then=Concat(
Value(settings.MEDIA_ROOT),
F(key),output_field=CharField()
)
),
default=Value(None),
output_field=CharField(null=True)
)
The problem is , this only works for public S3 . For private how can we do so so that we can get image on annotate? like using a custom django db function or something else? Any leads will be appreciated .
The database we are using is PostgreSQL
.
We are using boto3
and django-storages
to connect to our s3 bucket.
We are actually not trying to run it through a serializer , and we are getting the data directly by using annotate and values.