From 76b3592e1d486489da2ef7b5742d05b63ee96e29 Mon Sep 17 00:00:00 2001 From: worldstear <767209925@qq.com> Date: Mon, 23 May 2022 14:58:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=A4=96?= =?UTF-8?q?=E7=BD=91=E6=96=87=E4=BB=B6=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pig/admin/controller/FileController.java | 12 ++++++++++++ .../pig4cloud/pig/admin/service/SysFileService.java | 9 ++++++++- .../pig/admin/service/impl/SysFileServiceImpl.java | 11 +++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/FileController.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/FileController.java index d97ee74b..4e4d0698 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/FileController.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/FileController.java @@ -115,4 +115,16 @@ public class FileController { IoUtil.copy(resource.getInputStream(), response.getOutputStream()); } + /** + * 获取文件外网的访问地址 + * @param bucket + * @param fileName + * @return + */ + @Inner(false) + @GetMapping("/online/{bucket}/{fileName}") + public R onlineFile(@PathVariable String bucket, @PathVariable String fileName) { + return R.ok(sysFileService.onlineFile(bucket, fileName)); + } + } diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/SysFileService.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/SysFileService.java index 6d7baabf..e7808bce 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/SysFileService.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/SysFileService.java @@ -53,5 +53,12 @@ public interface SysFileService extends IService { * @return */ Boolean deleteFile(Long id); - + + /** + * 获取外网访问地址 + * @param bucket + * @param fileName + * @return + */ + String onlineFile(String bucket, String fileName); } diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysFileServiceImpl.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysFileServiceImpl.java index fb8a4fe9..0ac85099 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysFileServiceImpl.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysFileServiceImpl.java @@ -126,4 +126,15 @@ public class SysFileServiceImpl extends ServiceImpl impl this.save(sysFile); } + /** + * 默认获取文件的在线地址 + * @param bucket + * @param fileName + * @return + */ + @Override + public String onlineFile(String bucket, String fileName) { + return ossTemplate.getObjectURL(bucket, fileName, Duration.of(7, ChronoUnit.DAYS)); + } + }