如何从 S3Client 获取 IBM COS S3 存储详细信息的正确 URL?

问题描述 投票:0回答:1

IBM COS S3 的示例存储桶详细信息如下

Bucket Name: icos-abc-prod-01-abc-02
Endpoint:  https://icos.abc.us-region.internal.das

我们使用下面的代码来创建 S3Client 对象。

credentials = new BasicAWSCredentials(VAL_ACCESS_KEY_ID, VAL_SECRET_ACCESS_KEY);
                if (1==1) {
                    log.info("Trying to get file system of S3 Compatible.");
                    S3Client = AmazonS3ClientBuilder.standard()
                            .withCredentials(new AWSStaticCredentialsProvider(credentials))
                            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(
                                    VAL_END_POINT_REGION, "us-east-1"))
                            .build();
                    bucketName = VAL_BUCKET_NAME;
                }

有了这个代码,当我们执行的时候

if (S3Client.doesObjectExist(bucketName, tempTgtFileName))
{
}

它将主机名检查为bucketname.endpoint(不带https),即icos-abc-prod-01-abc-02.icos.abc.us-region.internal.das 这是不正确的。

预期的主机名应为 icos.abc.us-region.internal.das。

S3Client 对象出了什么问题?

amazon-s3 ibm-cloud
1个回答
0
投票

您需要切换到路径样式访问,以便 sdk 不会将存储桶名称作为主机名添加到前面

向构建器链添加一行:

.withPathStyleAccessEnabled(true)
© www.soinside.com 2019 - 2024. All rights reserved.