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;
}
————————————————
版权声明:本文为优快云博主「Legendary灬」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/qq_16272049/article/details/80041178