我不能通过Java访问S3,但可以通过AWS CLI访问。
我正在使用来自适用于MINIO的AWS SDK的凭据
// import statements
public class S3Application {
private static final AWSCredentials credentials;
private static String bucketName;
static {
//put your accesskey and secretkey here
credentials = new BasicAWSCredentials(
"Q3AM3UQ867SPQQA43P2F",
"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
);
}
public static void main(String[] args) throws IOException {
//set-up the client
AmazonS3 s3Client = AmazonS3ClientBuilder
.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://play.min.io:9000","us-east-1"))
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.build();
AWSS3Service awsService = new AWSS3Service(s3Client);
}
}这是我上面提到的代码的日志。
线程“主”com.amazonaws.SdkClientException中的异常:无法执行HTTP请求:连接重置.原因: java.net.SocketException:连接重置. 13 进程已完成,退出代码为%1
发布于 2019-09-24 22:22:35
您可能必须将PathStyle访问设置为true。https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/AmazonS3Builder.html#withPathStyleAccessEnabled-java.lang.Boolean-
像这样的代码可能有效。
// import statements
public class S3Application {
private static final AWSCredentials credentials;
private static String bucketName;
static {
//put your accesskey and secretkey here
credentials = new BasicAWSCredentials(
"Q3AM3UQ867SPQQA43P2F",
"zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
);
}
public static void main(String[] args) throws IOException {
//set-up the client
AmazonS3 s3Client = AmazonS3ClientBuilder
.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://play.min.io:9000","us-east-1"))
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withPathStyleAccessEnabled(true)
.build();
AWSS3Service awsService = new AWSS3Service(s3Client);
}
}https://stackoverflow.com/questions/58022293
复制相似问题