django-storages icon indicating copy to clipboard operation
django-storages copied to clipboard

Customisable expiration for s3 backend

Open Mogost opened this issue 2 years ago • 0 comments

I would like to be able to modify the behavior in terms of generating pre-signed urls. Now the generation of pre-signed URLs is based on the current time. This leads to the fact that the user refreshing the page will receive each time a new link and the browser cache in his case does not work. In order to override this behavior, it's essentially copying a lot of code, which I'd like to avoid.

https://github.com/jschneier/django-storages/blob/4ad22c3a23048cb5f44c11d4f38d75b8173fec22/storages/backends/s3boto3.py#L580-L582

I want to override this in order to have discrete values of expiration time, acting over some period of time.

It would be nice to have something like this to be able to modify behavior

...
def get_expiration(expire):
    return datetime.utcnow() + timedelta(seconds=expire)
...
expiration = self.get_expiration(expire)

image

Mogost avatar Feb 20 '23 17:02 Mogost