microsoft / AzureTipsAndTricks

Learn some of our favorite Azure tips and tricks—some long-standing, and new ones that have recently been added to become more productive with Azure. Star the repo now to shave hours off your coding tasks tomorrow.
http://azuredev.tips
Creative Commons Attribution 4.0 International
1.49k stars 489 forks source link

How to open a write stream to a container using Blob Client ? #149

Closed kanishka47 closed 2 years ago

kanishka47 commented 3 years ago

I am using latest the azure sdk Azure.Storage.Blobs version 12.9.1 for C# . I have to move all blobs from one container to another . I have listed all blobs but I am stuck at how to open an output stream to write a blob in another container .

List<string> files = new List<string>();

            var blobs = container.GetBlobs();
            foreach (var blob in blobs)
            {
                files.Add(blob.Name);
            }

              using (var zipOutputStream = new ZipOutputStream())   
                {
                    foreach (var blobFileName in files)
                    {
                        zipOutputStream.SetLevel(5);
                        var blob = dirwhereZip.GetBlobClient(blobFileName);
                        var entry = new ZipEntry(blobFileName);
                        zipOutputStream.PutNextEntry(entry);
                        blob.DownloadTo(zipOutputStream);
                    }
                    zipOutputStream.Finish();
                    zipOutputStream.Close();
                }

What should be the argument at var zipOutputStream = new ZipOutputStream() to open a stream and zip

erjuntun75 commented 2 years ago

@kanishka47 Thank you for the suggestion. We are working on creating a tip “How to move Azure Storage Blobs between containers” to replace tips #78 and #81, which are somewhat related to your suggestion.

https://microsoft.github.io/AzureTipsAndTricks/blog/tip78.html https://microsoft.github.io/AzureTipsAndTricks/blog/tip81.html

Lukejkw commented 1 year ago

@kanishka47 did you find a solution to this issue? Trying to do the same thing