我正在构建一个允许用户上传PDF文件以供其他用户下载的Web应用程序(python和Django)。如何防止用户上传嵌入在pdf中的病毒?PDF和Django中的病毒
更新: 我在使用clamcv的django片段中发现了此代码。这会做这份工作吗?
def clean_file(self):
file = self.cleaned_data.get('file', '')
#check a file in form for viruses
if file:
from tempfile import mkstemp
import pyclamav
import os
tmpfile = mkstemp()[1]
f = open(tmpfile, 'wb')
f.write(file.read())
f.close()
isvirus, name = pyclamav.scanfile(tmpfile)
os.unlink(tmpfile)
if isvirus:
raise forms.ValidationError(\
"WARNING! Virus \"%s\" was detected in this file. \
Check your system." % name)
return file
安装了病毒扫描和上传后,以及在存储之前扫描的文件... –