关于后端无法获取前端传来的超长字符串,导致数据被省略清空问题图片uuid路径问题
目录
关于后端无法获取前端传来的超长字符串,导致数据被省略清空问题(图片uuid路径问题)
在Elementui的图片上传时候,会出现图片路径因为太长而无法传输到后端的contoller层,在获取数据库的图片路径时候为空的问题
解决方法:
通过 HttpServletRequest request 将字符串直接上传到服务器上,因为是上传图片,只在本服务使用,所以无需永久储存,将路径储存到httpservlet服务器中即可
@RequestMapping("/upload")
@ResponseBody
public R<String> upload(MultipartFile file,HttpServletRequest request){
try {
String jpgname = UUID.randomUUID().toString();
path=basePath+jpgname+".jpg";
file.transferTo(new File(path));
path="../userimage/"+jpgname+".jpg";
} catch (IOException e) {
e.printStackTrace();
}
request.getSession().setAttribute("path",path);
return R.success(this.path);
}
然后通过http将图片信息下载
@RequestMapping("/download")
@ResponseBody
public String download(HttpServletRequest request){
String paths = (String) request.getSession().getAttribute("path");
return paths;
}