Click here to Skip to main content
15,884,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi I want to read a csv file from amazon s3 bucket nut not able to that.
below is my code

What I have tried:

C#
public static void readFile()
        {
            TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(accessKey, secretKey, Amazon.RegionEndpoint.USEast1));

            BasicAWSCredentials basicCredentials = new BasicAWSCredentials(accessKey, secretKey);
            AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey), Amazon.RegionEndpoint.USEast1);
            ListObjectsRequest request = new ListObjectsRequest();

            ListObjectsResponse response = s3Client.ListObjects(request.BucketName = bucketName, request.Prefix = csvFileName);

            foreach (S3Object obj in response.S3Objects)
            {
                try
                {
                    //string filename = directoryPath + "\\" + obj.Key;
                    //FileStream fs = File.Create(filename);
                    //fs.Close();
                    //Console.WriteLine("{0}", obj.Key);
                    fileTransferUtility.Download(csvFileName, bucketName, obj.Key);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message, ex.InnerException);
                }
            }
        }
Posted
Updated 13-Dec-21 2:25am
v2
Comments
Chris Copeland 13-Dec-21 8:26am    
What is the issue you're having? Are you seeing an exception, and if so what is the exception telling you is the issue? We can't know what the exact error is just by looking at this code.
guptaritu 14-Dec-21 4:51am    
No exceptions no errors but not getting the file which is stored in bucket
for example
bucket1\\bucket2\\abc.csv
I want to read abc.csv file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900