@@ -28,10 +28,10 @@ def client(self):
28
28
def build_attrs (self , * args , ** kwargs ):
29
29
attrs = super ().build_attrs (* args , ** kwargs )
30
30
31
- mime_type = attrs .get ('accept' , None )
31
+ accept = attrs .get ('accept' )
32
32
response = self .client .generate_presigned_post (
33
33
self .bucket_name , os .path .join (self .upload_folder , '${filename}' ),
34
- Conditions = self .get_conditions (mime_type ),
34
+ Conditions = self .get_conditions (accept ),
35
35
ExpiresIn = self .expires ,
36
36
)
37
37
@@ -48,18 +48,21 @@ def build_attrs(self, *args, **kwargs):
48
48
defaults ['class' ] = 's3file'
49
49
return defaults
50
50
51
- def get_conditions (self , mime_type ):
51
+ def get_conditions (self , accept ):
52
52
conditions = [
53
53
{"bucket" : self .bucket_name },
54
54
["starts-with" , "$key" , self .upload_folder ],
55
55
{"success_action_status" : "201" },
56
56
]
57
- if mime_type :
58
- top_type , sub_type = mime_type .split ('/' , 1 )
59
- if sub_type == '*' :
60
- conditions .append (["starts-with" , "$Content-Type" , "%s/" % top_type ])
61
- else :
62
- conditions .append ({"Content-Type" : mime_type })
57
+ if accept :
58
+ accept = accept .replace (' ' , '' ) # remove whitespaces
59
+ mime_types = accept .split (',' ) if accept else [] # catch empty string
60
+ for mime_type in mime_types :
61
+ top_type , sub_type = mime_type .split ('/' , 1 )
62
+ if sub_type == '*' :
63
+ conditions .append (["starts-with" , "$Content-Type" , "%s/" % top_type ])
64
+ else :
65
+ conditions .append ({"Content-Type" : mime_type })
63
66
else :
64
67
conditions .append (["starts-with" , "$Content-Type" , "" ])
65
68
0 commit comments