解决layui上传文件提示上传异常,实际文件已经上传成功的问题
时间:2021-01-30 10:22:27|栏目:JavaScript代码|点击: 次
layui上传文件提示上传异常,实际文件已经上传成功
原因:上传回调的方法接收的参数应该是json格式的,之前返回的是String,所以一直走异常的方法
@ResponseBody
@RequestMapping("/web/upload")
public JSONObject uploadSourceData(@RequestParam(value="file") MultipartFile file ){
String filePath = “”;
String fileName = filePath+System.currentTimeMillis()+"_"+file.getOriginalFilename(); //上传后的文件名 原始文件名加上时间戳
FileOutputStream out;
JSONObject resObj = new JSONObject();
resObj.put("msg", "ok");
try {
out = new FileOutputStream(new File(fileName));
IOUtils.copy(file.getInputStream(), out);
out.close();
} catch (Exception e) {
// TODO Auto-generated catch block
resObj.put("msg", "error");
e.printStackTrace();
}
return resObj;
}
上一篇:微信小程序 缓存(本地缓存、异步缓存、同步缓存)详解
栏 目:JavaScript代码
下一篇:利用 spin.js 生成等待效果(js 等待效果)
本文标题:解决layui上传文件提示上传异常,实际文件已经上传成功的问题
本文地址:http://www.codeinn.net/misctech/53612.html






