Configure the path style in the Java SDK Amazon S3

I am using AWS Java SDK provided by Amazon to interact with S3 service

It seems that by default, the SDK uses the virtual host style as the bucket (that is, the bucket is provided by bucket-name.s3.amazonaws.com. Example:

PUT / HTTP/1.1
Host: a-given-bucket.s3.amazonaws.com
Date: Tue,26 Jun 2012 10:39:40 GMT
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: 0

However, I need to use path style in my application, as follows:

PUT /a-given-bucket/ HTTP/1.1
Host: s3.amazonaws.com
Date: Thu,21 Jun 2012 16:27:32 GMT
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: 0

Can I use the path style in the Java SDK? What should I do in a positive situation? I've seen clientconfiguration and Amazon s3client classes, but I don't see any methods to do

My SDK version is 2.0.0 in important cases 0v201206151133.

thank you!

Fermin

PD. For simplicity, some titles have been omitted from the sample

Edit: this function (used to configure the URL path style used by Amazon S3 client) is very useful in case there is a dot (".) in your bucket HTTPS requests with virtual host style do not work, see this and this

Solution

The method with pathstyleaccess is not recommended Use the following instead:

AmazonS3 s3client = AmazonS3Client.builder()
            .withCredentials((new AWSStaticCredentialsProvider(credentials)))
            .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("host","region"))
            .withPathStyleAccessEnabled(true)
            .build();

Discard method:

It's ok now. I'm not sure when it will be launched, but it can be at least 1.7 8 version of Java AWS SDK

Simply call setclientoptions on your Amazon S3 instance:

AmazonS3 client = new AmazonS3Client(credentials);
client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true));
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>