我正在尝试使用Java从Amazon S3获取文件(http://docs.aws.amazon.com/AmazonS3/latest/dev/RetrievingObjectUsingJava.html),但是由于不知道对象键是什么,所以遇到了问题。
存储桶名称为
我得到这个输出:
存储桶名称为
testbucket
,在此存储桶中有一个名为files
的文件夹。如果我有一个名为image.jpeg
的文件,则对象键是什么?private static String bucketName = "testbucket";
private static String key="files/image.jpeg";
public static void main(String[] args) throws IOException {
AmazonS3 s3Client = new AmazonS3Client(new ProfileCredentialsProvider());
S3Object s3object = s3Client.getObject(new GetObjectRequest(
bucketName, key));
}
我得到这个输出:
21:43:54.054 [main] DEBUG com.amazonaws.request - Sending Request: GET https://adap-demo.s3.amazonaws.com /report_templates/Testreport_1.jrxml
Headers: (User-Agent: aws-sdk-java/1.10.30 Linux/4.4.0-70-generic
OpenJDK_64-Bit_Server_VM/25.121-b13/1.8.0_121, Content-Type:
application/x-www-form-urlencoded; charset=utf-8, )
21:43:54.164 [main] DEBUG c.a.services.s3.internal.S3Signer - Calculated
string to sign:
"GET
application/x-www-form-urlencoded; charset=utf-8
Sun, 02 Apr 2017 19:43:54 GMT
/adap-demo/report_templates/Testreport_1.jrxml"
Caught an AmazonClientException, which means the client encountered an
internal error while trying to communicate with S3, such as not being able
to access the network.
Error Message: Unable to calculate a request signature: Unable to
calculate a request signature: Empty key
files/image.jpeg
。要检查关键字,请点击文件并查看链接。链接应为https://s3-[region]..amazonaws.com/[bucket name]/[file key]
。 - Leon~/.aws/credentials
应该包含你的凭证)中?另外,如果你只想提供对象键和存储桶名称,getObject
有一个简写方式。 - Leon