Generate the given URL with the format: s3.amazonaws.com/bucket.name

I generate the assigned URLs, but this is problematic for period bucket names and SSL because of the * .s3.amazonaws certificate, as described here: http://shlomoswidler.com/2009/08/amazon-s3-gotcha-using -virtual-host.html

Is there a way to generate urls with the following format ?: http://s3.amazonaws.com/bucket.name/key

I did not see the options in the API. I suppose I can do this “manually” by rearranging the URL, but I would prefer to avoid hacking if it is not needed.

Based on Michael's answer, here is the code I'm using now:

public static URL bucketNameAfterS3Url(URL url) {

    int index = url.getHost().indexOf("s3");
    String host = url.getHost().substring(index);
    String bucket = url.getHost().substring(0, index - 1);
    URL toUse;
    try {
        toUse = new URL(url.getProtocol(), host, url.getPort(), '/' + bucket + url.getFile());
    } catch (MalformedURLException e) {
    }
    return toUse;
}
+4
source share
2 answers

, , , . bucket , .

, URL.

"lolcat.jpg" "-"...

https://example-bucket.s3.amazonaws.com/lolcat.jpg
https://s3.amazonaws.com/example-bucket/lolcat.jpg

URL , US-Standard.

, , , , .

. us-west-2, :

https://s3-us-west-2.amazonaws.com/example-bucket/lolcat.jpg

, , URL.

4, , . Signature Version 2 URL URL- - .

+3

S3 :

    // Configure the S3 client to generate urls with valid SSL certificates. With this setting we will get urls
    // like https://s3.amazonaws.com/bucket_name/... but if this is not set we will get urls like
    // https://bucket_name.s3.amazonaws.com/ which will cause the browser to complain about invalid SSL
    // certificates.
    s3Client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true));
+4

All Articles