[英]Retrieve 2 S3 objects and their content using only 1 request [C# AWSSDK]
我有以下文件 S3 存儲桶:
“桶名”
有沒有一種方法可以從“ BucketName/folder1/ ”路徑中檢索內容(即列出密鑰),這將在對 S3 的 1 個請求中為我提供**usa**
和**canada**
對象的文件。
目前,我有以下代碼向 S3 發出 2 個請求,我試圖避免檢索這兩個國家/地區的所有文件:
public List<string> GetShapefiles(string country)
{
var s3Request = new ListObjectsV2Request
{
BucketName = BucketName,
Delimiter = "/"
};
if (country == "US")
{
s3Request.Prefix = "BucketName/folder1/usa/";
return GetShapeFileList(s3Request);
}
else if (country == "Canada")
{
s3Request.Prefix = "BucketName/folder1/canada/";
return GetShapeFileList(s3Request);
}
}
private List<string> GetShapeFileList(ListObjectsV2Request request)
{
var result = new List<string>();
ListObjectsV2Response response;
do
{
response = S3_CLIENT.ListObjectsV2Async(request).Result;
foreach (var file in response.S3Objects.Where(f => f.Key.LastIndexOf('/') != f.Key.Length - 1))
{
result.Add(file.Key);
}
request.ContinuationToken = response.NextContinuationToken;
} while (response.IsTruncated);
return result;
}
所以理想情況下,我只想提出 1 個請求,讓我獲得美國和加拿大的所有 zip 文件,如下所示:
/usa/file1.zip
/usa/file2.zip
/canada/file1.zip
/canada/file2.zip
Amazon S3 不支持每個 GET 請求檢索多個數據范圍。
- https://docs.aws.amazon.com/AmazonS3/latest/dev/GettingObjectsUsingAPIs.html
你最好的選擇是繼續你正在做的事情——遍歷你的對象並檢索每個對象。 這可以同時或異步完成 - 我建議從 S3 並行獲取每個 object。 祝你好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.