|
|
|
@ -37,6 +37,7 @@ public class FileController extends BaseController {
|
|
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
|
|
if (fileName == null) return fail();
|
|
|
|
|
fileName = renameToUUID(fileName);
|
|
|
|
|
Map<String, Object> 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();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("上传出错", e);
|
|
|
|
|
return fail();
|
|
|
|
|
}
|
|
|
|
|
Map<String, Object> 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());
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("上传出错", e);
|
|
|
|
|
return fail();
|
|
|
|
|
}
|
|
|
|
|
ret.put("localPath", "/upload/" + fileName);
|
|
|
|
|
return data(ret);
|
|
|
|
|
}
|
|
|
|
|