Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generate_presigned_url method #238

Open
jjnesbitt opened this issue Sep 24, 2021 · 0 comments
Open

Add generate_presigned_url method #238

jjnesbitt opened this issue Sep 24, 2021 · 0 comments

Comments

@jjnesbitt
Copy link
Contributor

Here's a code snippet (taken from here) that represents what's currently required to generate a presigned URL from a model using S3FileField

storage = model.blob.storage
if isinstance(storage, S3Boto3Storage):
    client = storage.connection.meta.client
    url = client.generate_presigned_url(
        'get_object',
        Params={
            'Bucket': storage.bucket_name,
            'Key': asset.blob.blob.name,
        },
    )
    return HttpResponseRedirect(url)
elif isinstance(storage, MinioStorage):
    client = storage.client if storage.base_url is None else storage.base_url_client
    bucket = storage.bucket_name
    obj = model.blob.name
    url = client.presigned_get_object(bucket, obj)
    return HttpResponseRedirect(url)
else:
    raise ValueError(f'Unknown storage {storage}')

It seems to me that everything in this code snippet is accessible by an S3FileField instance, and could be included as a method on that model. @brianhelba does this seem viable/reasonable to you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Inbox
Development

No branches or pull requests

1 participant