圖檔上傳到伺服器位置 ,顯示 不使用路徑 + 圖檔名 ,而是使用 下載下傳流 顯示
@RequestMapping(value = "/downloadfile")
public void downloadfile(HttpServletRequest req, HttpServletResponse rsp) {
try {
// <meta http-equiv="Pragma" content="no-cache"/>
rsp.setHeader("Cache-Control", "no-cache");
rsp.setHeader("Pragma", "no-cache");
rsp.setDateHeader("Expires", 0);
String filename = req.getParameter("filename");
File file = new File(sysConfigService.getTmpdir() + File.separatorChar + filename);
ServletOutputStream out = rsp.getOutputStream();
FileInputStream in = new FileInputStream(file);
byte b[] = new byte[1024];
int len = 0;
while ((len = in.read(b)) != -1) {
out.write(b, 0, len);
}
out.flush();
out.close();
} catch (FileNotFoundException e) {
logger.warn(e.getMessage());
} catch (IOException e) {
logger.error("", e);
}
}
<img class="icon" src="/xxx/upload/downloadfile?filename=default-appicon.png">
捐助開發者
在興趣的驅動下,寫一個
免費
的東西,有欣喜,也還有汗水,希望你喜歡我的作品,同時也能支援一下。 當然,有錢捧個錢場(右上角的愛心标志,支援支付寶和PayPal捐助),沒錢捧個人場,謝謝各位。

謝謝您的贊助,我會做的更好!