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)); + } + }