0

I am working on a project where I need to get Zip files from S3 Bucket. I was able to copy these files one at a time to my EC2 instance using

  foreach (S3Object o in response.S3Objects)
        {

            GetObjectRequest requests = new GetObjectRequest();
            requests.BucketName = "mybucket";
            requests.Key = o.Key;
            GetObjectResponse responses = client.GetObject(requests);


            responses.WriteResponseStreamToFile(@"D:\myfile.zip");
            Console.WriteLine("{0}\t{1}\t{2}", o.Key, o.Size, o.LastModified);
        }

but I would like to unzip these files on the fly to a specific location instead of copy them locally. I tried the following but it did not work

 using (ZipArchive archive = ZipFile.OpenRead(responses.ResponseStream.ToString())) //unzip file 
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {

                       archive.ExtractToDirectory(myPath);

                    }
                }

            }

Thanks

BigFish
  • 87
  • 9

1 Answers1

0

ZipFile.OpenRead() takes a file name of a local file so that won't work. You can, however, unzip an archive in a MemoryStream (see this answer and this answer).

Community
  • 1
  • 1
jzonthemtn
  • 3,344
  • 1
  • 21
  • 30
  • I think that will not unzip the file to a local folder on my EC2 instance, correct? it reads the ZIP without unzipping it. I want to unzip the file to local folder on my EC2 instance. – BigFish Nov 16 '16 at 16:45