mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
uploads: Add an endpoint which forces a download.
This is most useful for images hosted in S3, which are otherwise always displayed in the browser.
This commit is contained in:
committed by
Tim Abbott
parent
d7b59c86ce
commit
abed174b12
@@ -385,7 +385,7 @@ def get_file_info(request: HttpRequest, user_file: File) -> Tuple[str, int, Opti
|
||||
return uploaded_file_name, uploaded_file_size, content_type
|
||||
|
||||
|
||||
def get_signed_upload_url(path: str) -> str:
|
||||
def get_signed_upload_url(path: str, download: bool = False) -> str:
|
||||
client = boto3.client(
|
||||
"s3",
|
||||
aws_access_key_id=settings.S3_KEY,
|
||||
@@ -393,9 +393,16 @@ def get_signed_upload_url(path: str) -> str:
|
||||
region_name=settings.S3_REGION,
|
||||
endpoint_url=settings.S3_ENDPOINT_URL,
|
||||
)
|
||||
params = {
|
||||
"Bucket": settings.S3_AUTH_UPLOADS_BUCKET,
|
||||
"Key": path,
|
||||
}
|
||||
if download:
|
||||
params["ResponseContentDisposition"] = "attachment"
|
||||
|
||||
return client.generate_presigned_url(
|
||||
ClientMethod="get_object",
|
||||
Params={"Bucket": settings.S3_AUTH_UPLOADS_BUCKET, "Key": path},
|
||||
Params=params,
|
||||
ExpiresIn=SIGNED_UPLOAD_URL_DURATION,
|
||||
HttpMethod="GET",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user