Multi File Upload type validation


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():
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
                raise ValidationError('File not supported!')

That’s because of the return statement inside the loop. If your first file is “application/pdf”, then the function will return f and not check the rest of the files.

Thanks @KenWhitesell that helped…I knew I was overlooking something