@@ -28,10 +28,10 @@ def client(self):
2828 def build_attrs (self , * args , ** kwargs ):
2929 attrs = super ().build_attrs (* args , ** kwargs )
3030
31- mime_type = attrs .get ('accept' , None )
31+ accept = attrs .get ('accept' )
3232 response = self .client .generate_presigned_post (
3333 self .bucket_name , os .path .join (self .upload_folder , '${filename}' ),
34- Conditions = self .get_conditions (mime_type ),
34+ Conditions = self .get_conditions (accept ),
3535 ExpiresIn = self .expires ,
3636 )
3737
@@ -48,18 +48,21 @@ def build_attrs(self, *args, **kwargs):
4848 defaults ['class' ] = 's3file'
4949 return defaults
5050
51- def get_conditions (self , mime_type ):
51+ def get_conditions (self , accept ):
5252 conditions = [
5353 {"bucket" : self .bucket_name },
5454 ["starts-with" , "$key" , self .upload_folder ],
5555 {"success_action_status" : "201" },
5656 ]
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 })
6366 else :
6467 conditions .append (["starts-with" , "$Content-Type" , "" ])
6568
0 commit comments