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

Ensure S3 Client is properly configured when generating a presigned URL #2301

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[flake8]
max-line-length = 88
...
select = C,E,F,W,B,B950
extend-ignore = E203, E501
per-file-ignores = __init__.py:F401
7 changes: 6 additions & 1 deletion onadata/libs/utils/image_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.core.files.storage import get_storage_class
from django.http import HttpResponse, HttpResponseRedirect
from botocore.exceptions import ClientError
from botocore.client import Config
from wsgiref.util import FileWrapper

from onadata.libs.utils.viewer_tools import get_path
Expand Down Expand Up @@ -67,7 +68,11 @@ def generate_aws_media_url(
):
s3 = get_storage_class("storages.backends.s3boto3.S3Boto3Storage")()
bucket_name = s3.bucket.name
s3_client = boto3.client("s3")
s3_config = Config(
signature_version=getattr("AWS_S3_SIGNATURE_VERSION", "s3v4"),
region_name=getattr("AWS_S3_REGION_NAME", ""),
)
s3_client = boto3.client("s3", config=s3_config)

# Generate a presigned URL for the S3 object
return s3_client.generate_presigned_url(
Expand Down