layui上传文件提示上传异常,实际文件已经上传成功
原因:上传回调的方法接收的参数应该是json格式的,之前返回的是String,所以一直走异常的方法
@ResponseBody
@RequestMapping("/web/upload")
public JSON uploadSourceData(@RequestParam(value="file") MultipartFile file ){
String filePath = “”;
String fileName = filePath+System.currentTimeMillis()+"_"+file.getOriginalFilename(); //上传后的文件名 原始文件名加上时间戳
FileOutputStream out;
JSON resObj = new JSON ();
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上传文件提示上传异常,实际文件已经上传成功的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
继续阅读与本文标签相同的文章
下一篇 :
如何增加用户的参与感?交互式推荐来了!
-
开发函数计算的正确姿势 —— 使用 ROS 进行资源编排
2026-05-18栏目: 教程
-
阿里云InfluxDB®基于TSI索引的数据查询流程
2026-05-18栏目: 教程
-
开发函数计算的正确姿势 —— 依赖安装方法一览
2026-05-18栏目: 教程
-
支付宝小程序“开闸放粮”,亿级流量扶持中小商家!
2026-05-18栏目: 教程
-
BFC 布局概念总结
2026-05-18栏目: 教程
