根据linux路径,以文件流的方式访问服务器图片
@GetMapping("/imgDownload")
public void getPic(HttpServletResponse response, String path) {
path = "/app/alarm_push/alarmpush/attach/000029cc/00002a5b/2022/测试文件上传_20220621104054A022.txt";
response.setContentType("image/png");
response.setHeader("content-disposition", "attachment;filename=back.png");
Connection conn = new Connection("服务器ip", 22);
try {
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword("用户", "密码");
if (!isAuthenticated) {
System.err.println("authentication failed");
}
SCPClient client = new SCPClient(conn);
client.get(path, response.getOutputStream());
conn.close();
} catch (IOException ex) {
System.out.println("连接服务器失败");
}
}