update 优化 OSS私有桶的临时URL获取方法
Signed-off-by: 秋辞未寒 <545073804@qq.com>
| | |
| | | /** |
| | | * 获取私有URL链接 |
| | | * |
| | | * @param objectKey 对象KEY |
| | | * @param second 授权时间 |
| | | * @param objectKey 对象KEY |
| | | * @param expiredTime 链接授权到期时间 |
| | | */ |
| | | public String getPrivateUrl(String objectKey, Integer second) { |
| | | public String getPrivateUrl(String objectKey, Duration expiredTime) { |
| | | // 使用 AWS S3 预签名 URL 的生成器 获取对象的预签名 URL |
| | | URL url = presigner.presignGetObject( |
| | | x -> x.signatureDuration(Duration.ofSeconds(second)) |
| | | x -> x.signatureDuration(expiredTime) |
| | | .getObjectRequest( |
| | | y -> y.bucket(properties.getBucketName()) |
| | | .key(objectKey) |
| | |
| | | OssClient storage = OssFactory.instance(oss.getService()); |
| | | // 仅修改桶类型为 private 的URL,临时URL时长为120s |
| | | if (AccessPolicyType.PRIVATE == storage.getAccessPolicy()) { |
| | | oss.setUrl(storage.getPrivateUrl(oss.getFileName(), 120)); |
| | | oss.setUrl(storage.getPrivateUrl(oss.getFileName(), Duration.ofSeconds(120))); |
| | | } |
| | | return oss; |
| | | } |