From 898779f9895071fe3b880f9d880fb704a7b4df64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E7=9A=87?= <236220500@qq.com> Date: Wed, 3 Jun 2020 22:26:32 +0800 Subject: [PATCH] 1 --- .../ic/activity/controller/FileController.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/kiisoo/ic/activity/controller/FileController.java b/src/main/java/com/kiisoo/ic/activity/controller/FileController.java index 3c4303c..4491a42 100644 --- a/src/main/java/com/kiisoo/ic/activity/controller/FileController.java +++ b/src/main/java/com/kiisoo/ic/activity/controller/FileController.java @@ -37,6 +37,7 @@ public class FileController extends BaseController { String fileName = file.getOriginalFilename(); if (fileName == null) return fail(); fileName = renameToUUID(fileName); + Map ret = new HashMap<>(); try { File targetPath = new File(uploadPath); if (!targetPath.exists()) { @@ -46,17 +47,16 @@ public class FileController extends BaseController { out.write(file.getBytes()); out.flush(); out.close(); + if(needMediaId != null) { + WxCpServiceOkHttpImpl serviceOkHttp = WxCpConfiguration.getCpService(WxCpConfiguration.APPLICATIONID); + WxMediaUploadResult result = serviceOkHttp.getMediaService().upload("image", new File(uploadPath + fileName)); + log.info("上传成功: {}", result); + ret.put("mediaId", result.getMediaId()); + } } catch (Exception e) { log.error("上传出错", e); return fail(); } - Map ret = new HashMap<>(); - if(needMediaId != null) { - WxCpServiceOkHttpImpl serviceOkHttp = WxCpConfiguration.getCpService(WxCpConfiguration.APPLICATIONID); - WxMediaUploadResult result = serviceOkHttp.getMediaService().upload("image", new File(uploadPath + fileName)); - log.info("上传成功: {}", result); - ret.put("mediaId", result.getMediaId()); - } ret.put("localPath", "/upload/" + fileName); return data(ret); }