11import logging
2- import os
2+ import pathlib
33import uuid
44
55from django .conf import settings
@@ -13,7 +13,7 @@ class S3FileInputMixin:
1313 """FileInput that uses JavaScript to directly upload to Amazon S3."""
1414
1515 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' ))
1717 expires = settings .SESSION_COOKIE_AGE
1818
1919 @property
@@ -29,7 +29,7 @@ def build_attrs(self, *args, **kwargs):
2929
3030 accept = attrs .get ('accept' )
3131 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}' ) ),
3333 Conditions = self .get_conditions (accept ),
3434 ExpiresIn = self .expires ,
3535 )
@@ -50,7 +50,7 @@ def build_attrs(self, *args, **kwargs):
5050 def get_conditions (self , accept ):
5151 conditions = [
5252 {"bucket" : self .bucket_name },
53- ["starts-with" , "$key" , self .upload_folder ],
53+ ["starts-with" , "$key" , str ( self .upload_folder ) ],
5454 {"success_action_status" : "201" },
5555 ]
5656 if accept and ',' not in accept :
@@ -66,10 +66,10 @@ def get_conditions(self, accept):
6666
6767 @cached_property
6868 def upload_folder (self ):
69- return os . path . join (
69+ return str ( pathlib . PurePosixPath (
7070 self .upload_path ,
7171 uuid .uuid4 ().hex ,
72- )
72+ )) # S3 uses POSIX paths
7373
7474 class Media :
7575 js = (
0 commit comments