🐛(backend) properly encode attachment upload content-disposition header
This patch changes the Content-Disposition header set on S3 PutObject requests when uploading attachments to be encoded using a Django helper, properly encoding UTF-8 in filenames. This fixes compatibility for uploading attachments with non ASCII file names to Garage, since the HTTP library used by Garage validates that HTTP Headers are ASCII only. Signed-off-by: networkException <[email protected]>
This commit is contained in:
@@ -27,6 +27,7 @@ from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.http import content_disposition_header
|
||||
from django.utils.text import capfirst, slugify
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
@@ -1661,11 +1662,19 @@ class DocumentViewSet(
|
||||
or serializer.validated_data["is_unsafe"]
|
||||
):
|
||||
extra_args.update(
|
||||
{"ContentDisposition": f'attachment; filename="{file_name:s}"'}
|
||||
{
|
||||
"ContentDisposition": content_disposition_header(
|
||||
as_attachment=True, filename=file_name
|
||||
)
|
||||
}
|
||||
)
|
||||
else:
|
||||
extra_args.update(
|
||||
{"ContentDisposition": f'inline; filename="{file_name:s}"'}
|
||||
{
|
||||
"ContentDisposition": content_disposition_header(
|
||||
as_attachment=False, filename=file_name
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
file = serializer.validated_data["file"]
|
||||
|
||||
Reference in New Issue
Block a user