
vue页面类似下载功能
如图:
vue代码
下载
前台绑定接口,后台实现功能代码:
String path = null;
String str=upgrade.substring(0, upgrade.indexOf("_"));
String s=upgrade.substring(str.length()+1, upgrade.length());
int flag = Integer.parseInt(s);
if(flag!=0){
//Linux客户端路径
if(flag == AppConfig.Virus_VERSION){
path = System.getProperty("user.dir") + File.separator + "client_upgrade" + File.separator
+upgrade+".tar.gz";
}else if(flag == AppConfig.Leak_VERSION) {
//Win客户端路径
path = System.getProperty("user.dir") + File.separator + "client" + File.separator
+upgrade+".tar.gz";
}
}
File file = new File(path);
//判断文件是否存在
if (!file.isFile()) {
throw new FortException(new FortError(StatusCode.ERROR, "文件不存在"));
}
String filename = FilenameUtils.getName(path);
response.setHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
try (FileInputStream fileInputStream = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(
response.getOutputStream())) {
FileCopyUtils.copy(bufferedInputStream, bufferedOutputStream);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 使用的是try-with-resources
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)