S3从特定文件夹下载 [英] S3 Download from a specific folder
问题描述
我的s3存储桶中有两个文件夹. 如何仅从bucket_one下载所有文件.
I have two folders inside my s3 bucket. How can I download all the files only from only bucket_one.
这是我用来从存储桶下载的代码. 现在,我想从该存储桶中的文件夹下载.
This is the code I am using to download from bucket. Now I want to download from a folder inside that bucket.
GetObjectRequest request = new GetObjectRequest(BucketName(),KeyName());
S3Object object = s3Client.getObject(request);
S3ObjectInputStream objectContent = object.getObjectContent();
IOUtils.copy(objectContent, new FileOutputStream(System.getProperty("user.home")+"//downloads//"+KeyName()));
谢谢
推荐答案
只需指出相关文件夹的完整路径
Just indicate the full path of the folder in question
将您的BucketName()
方法更改为类似于folderName()
的方式,该方式将为bucketName() + "/" + <yourfolder> + "/"
Change your BucketName()
method to be something like folderName()
which will be bucketName() + "/" + <yourfolder> + "/"
最后的"/"很重要,否则S3将在您的存储桶根文件夹中搜索文件
the "/" is important at the end otherwise S3 will search for a file within your bucket root folder
您可以使用它来更深入地了解文件夹结构:bucketName() + "/" + <folder1> + "/" + <folder2> + "/"
You can use the same to go deeper in your folder structure : bucketName() + "/" + <folder1> + "/" + <folder2> + "/"
这篇关于S3从特定文件夹下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!