增加获取外网文件链接

This commit is contained in:
worldstear 2022-05-23 14:58:50 +08:00
parent 4965260b62
commit 76b3592e1d
3 changed files with 31 additions and 1 deletions

View File

@ -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<String> onlineFile(@PathVariable String bucket, @PathVariable String fileName) {
return R.ok(sysFileService.onlineFile(bucket, fileName));
}
}

View File

@ -53,5 +53,12 @@ public interface SysFileService extends IService<SysFile> {
* @return
*/
Boolean deleteFile(Long id);
/**
* 获取外网访问地址
* @param bucket
* @param fileName
* @return
*/
String onlineFile(String bucket, String fileName);
}

View File

@ -126,4 +126,15 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> 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));
}
}