我正在尝试使用aws-sdk-java AwsS3client与minio存储进行通信。从CLI我可以做到:
aws --profile=minioplay --endpoint-url https://play.minio.io:9000 s3 cp logback.xml s3://miniohstest-jixusroqeb --debug
因此使用非默认配置文件和自定义端点。
不知道如何从java sdk执行此操作(我能够吗?)。
我粗略地将上面的awscli
命令翻译成了这个scala片段:
val cred = ...
val endpoint = "https://play.minio.io:9000"
val client = AmazonS3ClientBuilder
.standard()
.withCredentials(cred)
.withEndpointConfiguration(
new EndpointConfiguration(
endpoint,
AwsHostNameUtils.parseRegion(endpoint, AmazonS3Client.S3_SERVICE_NAME)
)
)
.build()
使用上述客户端我只能提出非常简单的请求,例如:
client.listBuckets().asScala.foreach(println(_))
哪个有效。但是当我尝试做一些先进的事情,比如:
val listRequest = new ListObjectsRequest()
.withBucketName("miniohstest-jixusroqeb")
//.withPrefix(r.getURI.getPath)
//.withDelimiter(delimiter)
val res = client.listObjects(listRequest)
res.getObjectSummaries.forEach(x => println(x.getKey))
它抛出以下异常:
Exception in thread "main" com.amazonaws.SdkClientException: Unable to execute HTTP request: miniohstest-jixusroqeb.play.minio.io
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1114)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1064)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743)
我做错了什么?
答案 0 :(得分:6)
我通过设置withPathStyleAccessEnabled(true)
来解决此问题。