Skip to content

Commit 53c5554

Browse files
committed
Switch to shorter base64 coded UUID in S3 key
1 parent 86a001a commit 53c5554

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

s3file/forms.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
import logging
23
import pathlib
34
import uuid
@@ -68,7 +69,9 @@ def get_conditions(self, accept):
6869
def upload_folder(self):
6970
return str(pathlib.PurePosixPath(
7071
self.upload_path,
71-
uuid.uuid4().hex,
72+
base64.urlsafe_b64encode(
73+
uuid.uuid4().bytes
74+
).decode('utf-8').rstrip('=\n'),
7275
)) # S3 uses POSIX paths
7376

7477
class Media:

tests/test_forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,4 @@ def test_media(self):
168168

169169
def test_upload_folder(self):
170170
assert ClearableFileInput().upload_folder.startswith('tmp/s3file/')
171-
assert len(ClearableFileInput().upload_folder) == 43
171+
assert len(ClearableFileInput().upload_folder) == 33

0 commit comments

Comments
 (0)