合规解决方案
要对用户请求数据进行控制。
在文件存储时,设计文件路径映射关系,如文件ID和存储路径的映射关系,在用户请求下载文件时,在请求参数中携带文件ID,服务器端根据文件ID来获取映射的文件路径,然后将文件内容返回客户端;或在请求文件处直接给出文件路径的链接。
映射文件路径下载:
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {try {ImageDao imgDao = new ImageDao();byte data[] = new byte[1];String imgID = request.getParameter("imgID");String imgName = imgDao.getImage(imgID);String imgKey = MD5Encrypt.MD5(imgName);//本地if (imageCache.containsKey(imgKey)) {data = (byte[]) imageCache.get(imgKey);} else {String imagePath = Consts.IMG_LOCAL_PAHT + imgName;//没有对该参数进行严格的验证和过滤,就拼接成完整的图片路径InputStream inputStream = null;File imageFile = new File(imagePath);logger.debug(imagePath + " " + imageFile.exists());if (imageFile.exists() && imageFile.isFile()) {inputStream = new FileInputStream(imagePath);int i = inputStream.available();data = new byte[i];inputStream.read(data);inputStream.close();imageCache.put(imgKey, data);} else {……}}response.setContentType("image/*");//将文件内容输出到客户端OutputStream outputStream = response.getOutputStream();outputStream.write(data);outputStream.close();}
<a href=“http://xx.xx.xx.xx/upload/file1.jpg”>
