我正在寻找一种方法来跟踪存储在亚马逊S3服务中的文件的下载。我下载了API,然后我很迷茫。我只是想知道我必须从API中使用哪些对象和方法才能获得存储在那里的文件的信息。我想跟踪下载,包括发出请求的地址。
感谢您提前。
答案 0 :(得分:1)
如果您正在谈论在日志记录存储桶中下载文件,我们会使用以下内容:
"loggingBucket"
以下是示例代码:
BasicAWSCredentials credentials =
new BasicAWSCredentials("accessKey", "secretAccessKey");
AmazonS3Client client = new AmazonS3Client(credentials);
for (ObjectListing listing = client.listObjects("loggingBucket");;
listing = client.listNextBatchOfObjects(listing)) {
// run through each listing to process it
for (S3ObjectSummary summary : listing.getObjectSummaries()) {
String bucketName = summary.getBucketName();
String fileName = summary.getKey();
S3Object object = client.getObject(bucketName, fileName);
S3ObjectInputStream stream = object.getObjectContent();
BufferedReader reader =
new BufferedReader(new InputStreamReader(stream));
... process the file here writing it locally or something
// delete the file afterwards
client.deleteObject(bucketName, fileName);
}
// we may need to get more files
if (!listing.isTruncated()) {
break;
}
}
如果这不是您想要的,请编辑您的帖子,以便我们为您提供更好的帮助。