调用后台接口,保存本地到nginx文件夹,使用通用返回对象返回nginx图片地址
@PostMapping("/upload") public ResponseResult<String> upLoad(@RequestParam("file") MultipartFile file) throws IOException { ResponseResult<String> result = new ResponseResult<>(); if (file.isEmpty()) { result.setCode(202); result.setMsg("上传失败"); } String filename = file.getOriginalFilename(); String path="D:/nginx-1.21.6/html/user_img/"; try { file.transferTo(new File(path+filename)); String url = "http://localhost:80/user_img/" + filename; result.setCode(200); result.setMsg("上传成功"); result.setData(url); }catch (RuntimeException e){ e.printStackTrace(); result.setCode(201); result.setMsg("系统错误"); } return result; }