Search code examples
amazon-s3timeoutboto3django-storage

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


Solution

  • 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.