上传图片base64 SringMVC+Tomcat 报错 Request header is too large

birdno1 2017-07-10 11:22:27
源码
 @RequestMapping(value="uploadfile",method = RequestMethod.POST, produces={"application/json;charset=UTF-8"})
@ResponseBody
public String file(HttpServletRequest req) throws ServletException,IOException
{
ResJson<String> res=new ResJson<String>();

String fileType = "png";
byte[] contentBytes = Base64.decodeBase64(Const.getPara(req, "file"));
int length = contentBytes.length;
ClassPathResource outFile = new ClassPathResource("/");

String p = outFile.getPath();
p = outFile.getFile().getParentFile().getParent();
String rePath = "/userfiles/";
String path = p + rePath;

File dir = new File(path);
if (!dir.exists())
dir.mkdirs();

String fileName = UUID.randomUUID().toString().replaceAll("-", "")
+ "." + fileType;

path = path + fileName;
rePath = rePath + fileName;

try {
FileCopyUtils.copy(contentBytes, new File(path));

} catch (IOException e) {
e.printStackTrace();
return JSON.toJSONString(res.getFailedJson("上传失败"));

}
return JSON.toJSONString(res.getSucJson("上传成功"));

}

报错

...全文
816 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lgc5834 2017-07-12
  • 打赏
  • 举报
回复
引用 6 楼 birdno1 的回复:
[quote=引用 4 楼 lgc5834 的回复:]
修改tomcat 的配置文件
还不行,可能得修改nginx的配置了

用的是tomcat啊[/quote]


我这是叫你修改tomcat配置啊
qq_35942223 2017-07-10
  • 打赏
  • 举报
回复
可以返回图片的路径,用js来转
birdno1 2017-07-10
  • 打赏
  • 举报
回复
那如何处理?这是给Android的接口,之前都用base64提交图片都没这个问题啊
minemine0418 2017-07-10
  • 打赏
  • 举报
回复
base64太长了
minemine0418 2017-07-10
  • 打赏
  • 举报
回复
同样的疑问 上传图片为啥要用这中方式??接口直接用MultipartFile不就可以了?
qq_35942223 2017-07-10
  • 打赏
  • 举报
回复
引用 5 楼 birdno1 的回复:
[quote=引用 3 楼 qq_35942223 的回复:] 可以返回图片的路径,用js来转
不太明白 [/quote] 这是调用接口吧?就返回图片路径让调用者转啊,为什么要转base64呢?
birdno1 2017-07-10
  • 打赏
  • 举报
回复
引用 4 楼 lgc5834 的回复:
修改tomcat 的配置文件 还不行,可能得修改nginx的配置了
用的是tomcat啊
birdno1 2017-07-10
  • 打赏
  • 举报
回复
引用 3 楼 qq_35942223 的回复:
可以返回图片的路径,用js来转
不太明白
lgc5834 2017-07-10
  • 打赏
  • 举报
回复
修改tomcat 的配置文件
还不行,可能得修改nginx的配置了

51,408

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧