修改mino公开桶返回地址

This commit is contained in:
mx 2025-01-03 10:22:25 +08:00
parent 91315492f3
commit b931d3c612
2 changed files with 8 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import com.pusong.common.oss.properties.OssProperties;
import com.pusong.common.oss.constant.OssConstant; import com.pusong.common.oss.constant.OssConstant;
import com.pusong.common.oss.entity.UploadResult; import com.pusong.common.oss.entity.UploadResult;
import com.pusong.common.oss.exception.OssException; import com.pusong.common.oss.exception.OssException;
import lombok.extern.slf4j.Slf4j;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.core.ResponseInputStream; import software.amazon.awssdk.core.ResponseInputStream;
@ -42,6 +43,7 @@ import java.time.Duration;
* *
* @author AprilWind * @author AprilWind
*/ */
@Slf4j
public class OssClient { public class OssClient {
/** /**
@ -154,6 +156,7 @@ public class OssClient {
throw new OssException("创建Bucket失败, 请核对配置信息:[" + e.getMessage() + "]"); throw new OssException("创建Bucket失败, 请核对配置信息:[" + e.getMessage() + "]");
} }
} else { } else {
log.error("createBucket error", ex);
throw new OssException("判断Bucket是否存在失败请核对配置信息:[" + ex.getMessage() + "]"); throw new OssException("判断Bucket是否存在失败请核对配置信息:[" + ex.getMessage() + "]");
} }
} }
@ -329,6 +332,9 @@ public class OssClient {
.url(); .url();
return url.toString(); return url.toString();
} }
public String getPublicUrl(String objectKey) {
return getUrl() + "/" + objectKey;
}
/** /**
* 上传 byte[] 数据到 Amazon S3使用指定的后缀构造对象键 * 上传 byte[] 数据到 Amazon S3使用指定的后缀构造对象键

View File

@ -279,6 +279,8 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
// 仅修改桶类型为 private 的URL临时URL时长为120s // 仅修改桶类型为 private 的URL临时URL时长为120s
if (AccessPolicyType.PRIVATE == storage.getAccessPolicy()) { if (AccessPolicyType.PRIVATE == storage.getAccessPolicy()) {
oss.setUrl(storage.getPrivateUrl(oss.getFileName(), 120)); oss.setUrl(storage.getPrivateUrl(oss.getFileName(), 120));
}else{
oss.setUrl(storage.getPublicUrl(oss.getFileName()));
} }
return oss; return oss;
} }