我需要在Spring 3 MVC应用程序中扫描上传的文件以检测病毒,并向用户显示适当的消息。
目前,我已经使用Spring MVC 3配置了文件上传。一旦控制器接收到文件,我必须检查病毒的存在。如果文件被感染了任何病毒,那么应用程序应该拒绝该文件并向用户显示一个特定的消息。
您有关于如何在Java Spring MVC应用程序中实现这一点的想法吗?我正在使用的Spring版本是3.2.4。
非常感谢您的帮助/指导。
谢谢!
目前,我已经使用Spring MVC 3配置了文件上传。一旦控制器接收到文件,我必须检查病毒的存在。如果文件被感染了任何病毒,那么应用程序应该拒绝该文件并向用户显示一个特定的消息。
您有关于如何在Java Spring MVC应用程序中实现这一点的想法吗?我正在使用的Spring版本是3.2.4。
非常感谢您的帮助/指导。
谢谢!
首先,您需要检查已安装的防病毒软件提供了什么类型的API。
如果提供了任何Java API(例如AVG API),则必须按以下方式使用:
public void scanFile(byte[] fileBytes, String fileName)
throws IOException, Exception {
if (scan) {
AVClient avc = new AVClient(avServer, avPort, avMode);
if (avc.scanfile(fileName, fileBytes) == -1) {
throw new VirusException("WARNING: A virus was detected in
your attachment: " + fileName + "<br>Please scan
your system with the latest antivirus software with
updated virus definitions and try again.");
}
}
}
String[] commands = new String[5];
commands[0] = "cmd";
commands[1] = "/c";
commands[2] = "C:\\Program Files\\AVG\\AVG10\\avgscanx.exe";
commands[3] = "/scan=" + filename;
commands[4] = "/report=" + virusoutput;
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(commands);