Hello,
I am trying to validate the mime type of multiple file upload. I only want to allow ‘application/pdf’ and am running into an issue. When multiple files are uploaded, the whole list is being seen as 1 mime type. If I upload 1 file I can parse properly but not when multiple files are uploaded. I am calling my own clean method on a form from views. Below is the relevant view lines and clean method from forms.
if file_form.is_valid():
file_form.clean_files()
def clean_files(self):
"""Make sure only pdf can be uploaded."""
for f in self.files.getlist("files"):
if f.content_type == "application/pdf":
return f
else:
raise ValidationError('File not supported!')