mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 00:20:43 -04:00
Limit length of filename
S3 has a limit of 2kb for metadata: > the user-defined metadata is limited to 2 KB in size. The size of > user-defined metadata is measured by taking the sum of the number of > bytes in the UTF-8 encoding of each key and value. – https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#object-metadata This means we have a limit of 1870 bytes for the filename: ```python encoded = 'notification_count50000template_id665d26e7-ceac-4cc5-82ed-63d773d21561validTrueoriginal_file_name'.encode('utf-8') sys.getsizeof(b) >>> 130 2000-130 >>> 1870 ``` Or, in other words, ~918 characters: ```python sys.getsizeof(('ü'*918).encode('utf-8')) >>> 1869 ```
This commit is contained in:
@@ -46,6 +46,7 @@ from app.utils import (
|
||||
get_errors_for_csv,
|
||||
get_help_argument,
|
||||
get_template,
|
||||
unicode_truncate,
|
||||
user_has_permissions,
|
||||
)
|
||||
|
||||
@@ -555,7 +556,10 @@ def _check_messages(service_id, template_id, upload_id, preview_row, letters_as_
|
||||
notification_count=len(recipients),
|
||||
template_id=str(template_id),
|
||||
valid=True,
|
||||
original_file_name=request.args.get('original_file_name'),
|
||||
original_file_name=unicode_truncate(
|
||||
request.args.get('original_file_name', ''),
|
||||
1872
|
||||
),
|
||||
)
|
||||
else:
|
||||
session['file_uploads'].pop(upload_id)
|
||||
|
||||
Reference in New Issue
Block a user