Reputation: 5670
I am downloading some files from amazon s3 like this
private static readonly IAmazonS3 _amazonS3Client = AWSClientFactory.CreateAmazonS3Client(
AccessKey,
SecretKey,
Config
);
var request = new ListObjectsRequest {BucketName = BucketName};
ListObjectsResponse response = _amazonS3Client.ListObjects(request);
foreach (S3Object o in response.S3Objects)
{
var objRequest = new GetObjectRequest
{
BucketName = BucketName,
Key = o.Key
};
GetObjectResponse objResponse = _amazonS3Client.GetObject(objRequest);
objResponse.WriteResponseStreamToFile(ConfigurationManager.AppSettings["TargetLocation"] + o.Key);
}
This works well, Now I have created a folder inside Bucket, and I want to download only the files inside that bucket. Can any one point out the correct approach to achieve this?
Upvotes: 2
Views: 5657
Reputation: 46879
Just set your bucketname as so: bucketname/foldername.
So If you have a bucket called 'MyBucket' and a folder within that bucket called MyFolder, than you would do:
var objRequest = new GetObjectRequest
{
BucketName = "MyBucket/MyFolder",
Key = o.Key
};
Upvotes: 5