首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在Spring3MVC应用程序中实现文件上传的病毒扫描

如何在Spring3MVC应用程序中实现文件上传的病毒扫描
EN

Stack Overflow用户
提问于 2014-03-26 13:46:10
回答 1查看 13.3K关注 0票数 5

我必须对上传的文件进行病毒扫描,并在Spring3MVC应用程序中向用户显示相应的消息。

目前我已经使用Spring MVC 3配置了文件上传。一旦在控制器中接收到文件,我就必须检查是否存在病毒,如果文件感染了任何病毒,那么应用程序应该拒绝该文件并向用户显示特定的消息。

关于如何在Java Spring MVC应用程序中实现这一点的任何想法。我使用的spring版本是3.2.4。

在这个方向上的任何帮助/指示都将不胜感激。

非常感谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-26 13:53:57

首先,你必须检查你安装的杀毒软件提供了什么类型的API。

如果提供了Java API (如AVG API),则必须使用它,如下所示:

代码语言:javascript
运行
复制
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.");
      }
   }
}

如果安装的杀毒软件没有提供Java API,您仍可以使用命令行调用它,如下所示:

代码语言:javascript
运行
复制
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);

有一篇有趣的文章供您参考:Implementing an Anti-Virus File Scan in JEE Applications

希望这对你有帮助。

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22652489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档