I'm generating presigned urls but its problematic for bucket names with periods 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 didn't see an option in the API. I'm guessing I can do it "manually" by rearranging the url, but I'd rather avoid a hack if its not necessary.
Based on Michael's answer here is the code I'm now using:
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;
}
Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that contains the object that you want a presigned URL for. In the Objects list, select the object that you want to create a presigned URL for.
Bucket names must not be formatted as an IP address (for example, 192.168. 5.4). Bucket names must not start with the prefix xn-- . Bucket names must not end with the suffix -s3alias .
Nothing could be easier, just select all files you want to generate URLs for and click the “Web URL” button on the toolbar. You will see the list of URLs for each of the selected files. Click copy to clipboard button and you are ready to paste URLs to other programs such as an HTML files editor.
An S3 bucket can be accessed through its URL. The URL format of a bucket is either of two options: http://s3.amazonaws.com/[bucket_name]/ http://[bucket_name].s3.amazonaws.com/
The S3 client allows you to set an option to configure this:
// 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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With