一、不在同一台主机,通过给对方文件的方式

Controller

@RequestMapping(value = "/down/{uuid}", method = RequestMethod.GET)
  @ResponseBody
  public void downloadImage(@PathVariable("uuid") final String uuid, HttpServletResponse response) {
    flService.downImage(uuid, response);
  }

service

	void downImage(String uuid, HttpServletResponse response);

serviceImpl

@Override
	public void downImage(String uuid, HttpServletResponse response) {
		//response.setHeader("Content-Disposition", "attachment;fileName=" + "asdf.jpg"); //下载
		response.setContentType("image/png");//显示
		String realPath = "C:\\Users\\Public\\Pictures\\Sample Pictures\\asdf.jpg";
		InputStream fileInputStream;
		try {
			fileInputStream = new FileInputStream(realPath );
			OutputStream outputStream = response.getOutputStream();
			IOUtils.copy(fileInputStream, outputStream);
			outputStream.close();
			fileInputStream.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

实现文件下载

response.setHeader("Content-Disposition", "attachment;fileName=" + "asdf.jpg");

实现文件在浏览器显示

response.setContentType("image/png");

二、通过nginx代理的方式访问。

nginx.conf配置

spacer.gif$A2OW@`DJCNT%2Y)XS3[5FC.png

location ~ ^/(img/|images/) {
          root C:/Users/Public/Pictures;
          access_log off;
          expires max;
        }

效果如下:

image.png

访问路径为:http://localhost:80/images/aaa.png