Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an AWS S3 object to never expire in Django Storages?

I am using django-storage (which uses Boto3 internally) to upload images. I am successfully able to do so and the return URL I get is of this format:

https://.s3.amazonaws.com/foo.jpg?Signature=&AWSAccessKeyId=&Expires=1513089114

where Signature and AWSAccessKeyId are filled in as well.

Now, I need to give this URL directly to Mobile Developers and I can't have the timeout set so late. I need it for many years or potentially always accessible. What is a good way to do so? What is the solution

like image 824
tsaebeht Avatar asked Dec 06 '22 12:12

tsaebeht


2 Answers

On glancing through the django-storages S3 Docs , I see there is a provision for

AWS_QUERYSTRING_EXPIRE which states

The number of seconds that a generated URL is valid for.

So if you wanted the link to be valid for 5 years from now, you can just add the corresponding number of seconds here which would amount to 157784630

So in conclusion, just add the following in your settings.py

AWS_QUERYSTRING_EXPIRE = '157784630'

This doesn't really seem like good practice to me but more like a convenient hack/workaround instead.

like image 128
bholagabbar Avatar answered Jan 13 '23 15:01

bholagabbar


If your S3 bucket is public, you can use this setting to turn off query parameter authentication.

Setting AWS_QUERYSTRING_AUTH to False to remove query parameter authentication
from generated URLs. This can be useful if your S3 buckets are public.
like image 21
hannah Avatar answered Jan 13 '23 15:01

hannah