From bb5e30e352b0e321a62ef12e237cf0afdb16a1ca Mon Sep 17 00:00:00 2001 From: x ronger Date: Wed, 18 Dec 2019 01:15:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=8A=9F=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/api/common/UploadController.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/web/api/common/UploadController.java b/src/main/java/com/rymcu/vertical/web/api/common/UploadController.java index 0146f1a..83f3c99 100644 --- a/src/main/java/com/rymcu/vertical/web/api/common/UploadController.java +++ b/src/main/java/com/rymcu/vertical/web/api/common/UploadController.java @@ -26,11 +26,12 @@ import java.util.Set; @RequestMapping("/api/v1/upload") public class UploadController { + private final static String UPLOAD_SIMPLE_URL = "/api/upload/file"; private final static String UPLOAD_URL = "/api/upload/file/batch"; public static final String ctxHeadPicPath = "/usr/local/src/tomcat-hp/webapps/vertical"; @PostMapping("/file") - public GlobalResult uploadPicture(@RequestParam(value = "file", required = false) MultipartFile multipartFile, Integer type, HttpServletRequest request){ + public GlobalResult uploadPicture(@RequestParam(value = "file", required = false) MultipartFile multipartFile,@RequestParam(defaultValue = "1")Integer type, HttpServletRequest request){ if (multipartFile == null) { return GlobalResultGenerator.genErrorResult("请选择要上传的文件"); } @@ -54,24 +55,20 @@ public class UploadController { } String localPath = Utils.getProperty("resource.file-path")+"/"+typePath+"/"; - Map succMap = new HashMap(10); - Set errFiles = new HashSet(); String orgName = multipartFile.getOriginalFilename(); String fileName = System.currentTimeMillis()+"."+ FileUtils.getExtend(orgName).toLowerCase(); String savePath = file.getPath() + File.separator + fileName; + Map data = new HashMap(2); File saveFile = new File(savePath); try { FileCopyUtils.copy(multipartFile.getBytes(), saveFile); - succMap.put(orgName,localPath+fileName); + data.put("url", localPath+fileName); } catch (IOException e) { - errFiles.add(orgName); + data.put("message", "上传失败!"); } - Map data = new HashMap(2); - data.put("errFiles",errFiles); - data.put("succMap",succMap); return GlobalResultGenerator.genSuccessResult(data); } @@ -122,6 +119,19 @@ public class UploadController { return GlobalResultGenerator.genSuccessResult(data); } + @GetMapping("/simple/token") + public GlobalResult uploadSimpleToken(HttpServletRequest request) throws BaseApiException { + String authHeader = request.getHeader(JwtConstants.AUTHORIZATION); + if(StringUtils.isBlank(authHeader)){ + throw new BaseApiException(ErrorCode.UNAUTHORIZED); + } + TokenUser tokenUser = UserUtils.getTokenUser(authHeader); + Map map = new HashMap(2); + map.put("uploadToken", tokenUser.getToken()); + map.put("uploadURL", UPLOAD_SIMPLE_URL); + return GlobalResultGenerator.genSuccessResult(map); + } + @GetMapping("/token") public GlobalResult uploadToken(HttpServletRequest request) throws BaseApiException { String authHeader = request.getHeader(JwtConstants.AUTHORIZATION);