def clean_file(self):
content = self.cleaned_data[u'file']
filename, extension = os.path.splitext(content.name)
if self.check_extension:
if re.match(self._options['acceptFileTypes'], extension, flags=re.I) is None:
raise forms.ValidationError('acceptFileTypes')
if self.check_content_type:
content_type = magic.from_buffer(content.read(1024), mime=True)
if content_type.lower() in self._options['allowedContentTypes']:
if content._size > self._options['maxFileSize']:
raise forms.ValidationError("maxFileSize")
else:
raise forms.ValidationError("acceptFileTypes")
return content
评论列表
文章目录