如何解决layui上传文件提示上传异常,实际文件已经上传成功的问题

这篇文章给大家分享的是有关如何解决layui上传文件提示上传异常,实际文件已经上传成功的问题的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

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;
}

感谢各位的阅读!关于“如何解决layui上传文件提示上传异常,实际文件已经上传成功的问题”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!