zhangjinli 3 years ago
parent 04f093e7c7
commit 5e669c2e15

@ -49,6 +49,8 @@ public class UtilsController {
@Value("${web.uploadPath}")
private String path;
@Value("${web.cdn}")
private String cdn;
@Operation(summary = "上传")
@PostMapping("/upload")
@ -106,9 +108,9 @@ public class UtilsController {
@ResponseBody
public JSONObject upload2(@RequestParam("file") MultipartFile file, @RequestParam(required = false) String name) {
JSONObject res = new JSONObject();
res.put("errno",1);
res.put("errno", 1);
if (file.isEmpty()) {
res.put("message","请选择文件");
res.put("message", "请选择文件");
return res;
}
String fileName = file.getOriginalFilename();//文件名
@ -119,16 +121,16 @@ public class UtilsController {
}
try {
file.transferTo(dest);
res.replace("errno",0);
res.replace("errno", 0);
JSONObject obj = new JSONObject();
obj.put("alt", fileName);
obj.put("url", "/upload/" + newFileName);
res.put("data",obj);
obj.put("url", cdn + "/upload/" + newFileName);
res.put("data", obj);
return res;
} catch (IOException e) {
e.printStackTrace();
}
res.put("message","上传失败");
res.put("message", "上传失败");
return res;
}

@ -54,6 +54,7 @@ mybatis-plus:
web:
apiPath: com.zh.project0512.controller
uploadPath: /www/wwwroot/project0512/upload/
cdn: http://cdn.sws010.com
#springdoc:
# swagger-ui:

Loading…
Cancel
Save