1
1
import logging
2
- import os
2
+ import pathlib
3
3
import uuid
4
4
5
5
from django .conf import settings
@@ -13,7 +13,7 @@ class S3FileInputMixin:
13
13
"""FileInput that uses JavaScript to directly upload to Amazon S3."""
14
14
15
15
needs_multipart_form = False
16
- upload_path = getattr (settings , 'S3FILE_UPLOAD_PATH' , os . path . join ('tmp' , 's3file' ))
16
+ upload_path = getattr (settings , 'S3FILE_UPLOAD_PATH' , pathlib . PurePosixPath ('tmp' , 's3file' ))
17
17
expires = settings .SESSION_COOKIE_AGE
18
18
19
19
@property
@@ -29,7 +29,7 @@ def build_attrs(self, *args, **kwargs):
29
29
30
30
accept = attrs .get ('accept' )
31
31
response = self .client .generate_presigned_post (
32
- self .bucket_name , os . path . join (self .upload_folder , '${filename}' ),
32
+ self .bucket_name , str ( pathlib . PurePosixPath (self .upload_folder , '${filename}' ) ),
33
33
Conditions = self .get_conditions (accept ),
34
34
ExpiresIn = self .expires ,
35
35
)
@@ -50,7 +50,7 @@ def build_attrs(self, *args, **kwargs):
50
50
def get_conditions (self , accept ):
51
51
conditions = [
52
52
{"bucket" : self .bucket_name },
53
- ["starts-with" , "$key" , self .upload_folder ],
53
+ ["starts-with" , "$key" , str ( self .upload_folder ) ],
54
54
{"success_action_status" : "201" },
55
55
]
56
56
if accept and ',' not in accept :
@@ -66,10 +66,10 @@ def get_conditions(self, accept):
66
66
67
67
@cached_property
68
68
def upload_folder (self ):
69
- return os . path . join (
69
+ return str ( pathlib . PurePosixPath (
70
70
self .upload_path ,
71
71
uuid .uuid4 ().hex ,
72
- )
72
+ )) # S3 uses POSIX paths
73
73
74
74
class Media :
75
75
js = (
0 commit comments