我正在尝试使用 Java ( http://docs.aws.amazon.com/AmazonS3/latest/dev/RetreeringObjectUsingJava.html )获取存储在 Amazon S3 中的文件,但我对对象键有问题,因为我不这样做不知道那是什么。
存储桶名称是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));
}
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
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
Run Code Online (Sandbox Code Playgroud)
简短的回答:在您的具体情况下,对象键是files/image.jpg
从技术角度来说,Amazon S3 是一个简单的基于密钥的对象存储。存储数据时,您分配一个唯一的对象键,稍后可用于检索数据。S3数据模型是扁平结构:您创建一个存储桶,存储桶存储对象。不存在“子存储桶”或子文件夹的层次结构。但是,您可以使用键名称前缀推断逻辑层次结构。
在您的情况下,前缀是files/,对象名称是image.jpg。键是与对象名称连接的前缀。
例如,传统的基于文件的结构及其目录如下所示:
- files
- index.html
- images
- logo.png
- photo.jpg
Run Code Online (Sandbox Code Playgroud)
将转换为 S3 上的以下平面结构,其中以下每一行代表各个对象的键:
files/index.html
files/images/logo.png
files/images/photo.jpg
Run Code Online (Sandbox Code Playgroud)
您可以在此处了解有关 Amazon S3 对象密钥的创建和使用的更多信息: https: //docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html
| 归档时间: |
|
| 查看次数: |
22696 次 |
| 最近记录: |