def clean_file(self):
pdf = self.cleaned_data['file']
if not pdf:
raise ValidationError(_('no file'))
# pdf magic check
if pdf.read(4) != PDF_MAGIC:
raise ValidationError(_('This file is not a PDF document.'))
pdf.seek(0)
# sanitization
try:
f = decrypt_pdf(pdf)
except ValueError:
raise ValidationError(_('The PDF-File seems to broken. For more Information click on the question mark in the sidebar.'))
f.seek(0)
return UploadedFile(f, content_type='application/pdf', name='upload.pdf')
评论列表
文章目录