this is a basic question, not very advanced, but I am a bit stuck.
I am trying to get the first n bytes of a file hosted on s3. I understand the basic building block to the issue. I know how to get the bytes. Here is an example from the AmazonS3
GET /example-object HTTP/1.1
Host: example-bucket.s3.amazonaws.com
x-amz-date: Fri, 28 Jan 2011 21:32:02 GMT
Range: bytes=0-9
Authorization: AWS AKIAIOSFODNN7EXAMPLE:Yxg83MZaEgh3OZ3l0rLo5RTX11o=
Sample Response with Specified Range of the Object Bytes
Now I have an s3 url, like this:
http://s3.amazonaws.com/bucket-name/foo/1/2/3/4/file.jpg
How do I translate this, into the kind of request specified in the docs? I know this is remedial, but I am stuck, this feels somewhat opaque, though that could just be me.
Please help me deconstruct the s3 url to the components of the GET request example. Help is appreciated!
UPDATE: If I am to Use the GetObjectRequest
api, what would I use for the bucket and key in the constructor?
UPDATE2: In other words is it as simple as
// modelled after http://s3.amazonaws.com/foo/
private String s3UrlToBucket(String s3Url)
{
Pattern pattern = Pattern.compile("^https?://[^/]+/([^/]+)/.*$");
Matcher matcher = pattern.matcher(s3Url);
if(matcher.find())
{
return matcher.group(1);
}
return null;
}
// modelled after http://s3.amazonaws.com/foo/1/2/3/4.jpg
private String s3UrlToKey(String s3Url)
{
Pattern pattern = Pattern.compile("^https?://[^/]+/[^/]+/(.*)$");
Matcher matcher = pattern.matcher(s3Url);
if(matcher.find())
{
return matcher.group(1);
}
return null;
}
UPDATE 3: Can you please explain to me what the key refers to???
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…