
具体功能如图:上传按钮
vue前台代码:
上传
vue绑定方法:
handleRemove(file, fileList) {
console.log(file, fileList);
},
handleProgress(event, file, fileList){
this.loading = Loading.service({
lock: true,
text: '程序正在升级,请耐心等待;或者完毕后手动刷新',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
},
handlePreview(file) {
console.log(file);
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}?`);
},
handleSuccess(res, file, fileList) {
console.log(res);
if (res.flag) {
this.$message.success(res.message);
this.findUpgradeFileVersion();
} else {
this.$message.error(res.message);
}
},
handleError(res, file, fileList) {
let errorStr = res.toString();
let errorStr2 = errorStr.replace("Error:","");
const Error = JSON.parse(errorStr2);
this.$message.error(Error.error_description);
this.loading.close()
},
Java后台代码实现:代码仅供参考,根据具体业务,再进行修改
public Result getUploadFile(@RequestBody MultipartFile file)
throws IOException {
if (file != null) {
//文件大小 KB单位
long size = file.getSize();
//获取上传文件的原文件名
String dirPath = System.getProperty("user.dir") + File.separator + "client_upgrade";
String src_file_name = file.getOriginalFilename();
//储存文件
String savePath = dirPath + File.separator + src_file_name;
boolean saveFile = upgradeUtil.saveFileForClient(file, savePath);
if (!saveFile) {
throw new FortException(new FortError(StatusCode.ERROR, "文件存储失败"));
}
//声明json序列化对象
// ObjectMapper mapper = new ObjectMapper();
//解压客户端升级包,读取新版本号和版本描述
Map map = upgradeUtil.getClientVerAndDes(savePath, dirPath, src_file_name);
if (map == null) {
throw new FortException(new FortError(StatusCode.ERROR, "获取版本信息及其升级文件名失败"));
}
//获取当前登录用户名
//在security中获取认证后的对象
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//获取当前登录的对象
User user = (User) authentication.getPrincipal();
return new Result(true, StatusCode.OK, "上传成功");
} else {
return new Result(false, StatusCode.ERROR, "上传失败");
}
}
@RequestMapping("/findUpgradeFileVersion")
public Result findUpgradeFileVersion() {
List upgradeFileList = upgradeFileService
.findUpgradeFile();
return new Result(true, StatusCode.OK, "成功", upgradeFileList);
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)