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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With