mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-19 14:03:52 -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:
@@ -568,3 +568,8 @@ class GovernmentEmailDomain(AgreementInfo):
|
||||
))
|
||||
except StopIteration:
|
||||
raise NotGovernmentEmailDomain()
|
||||
|
||||
|
||||
def unicode_truncate(s, length):
|
||||
encoded = s.encode('utf-8')[:length]
|
||||
return encoded.decode('utf-8', 'ignore')
|
||||
|
||||
Reference in New Issue
Block a user