Q: Download blobs into Upload blob from zip stream
ScottKane opened this issue · comments
ScottKane commented
Which service(blob, file, queue, table) does this issue concern?
Blob
Which version of the SDK was used?
Azure.Storage.Blobs:12.0.0 - Nuget
Which platform are you using? (ex: .NET Core 2.1)
NET Core 3.0
What problem was encountered?
containerClient.UploadBlobAsync fails to upload zip stream into blob
How can we reproduce the problem in the simplest way?
static async Task Main()
{
await ZipAzureBlob("testblob");
}
static async Task ZipAzureBlob(string containerName)
{
var blobServiceClient = new BlobServiceClient("");
var containerClient = blobServiceClient.GetBlobContainerClient(containerName);
using (MemoryStream zipStream = new MemoryStream())
{
using (ZipArchive zip = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
{
await foreach (BlobItem blobItem in containerClient.GetBlobsAsync())
{
ZipArchiveEntry entry = zip.CreateEntry(blobItem.Name);
using (Stream entryStream = entry.Open())
{
var blobClient = containerClient.GetBlobClient(blobItem.Name);
Console.WriteLine($"Adding file to zip archive: {blobItem.Name}");
await blobClient.DownloadToAsync(entryStream);
}
}
}
Console.WriteLine($"Uploading zip archive {containerName}.zip to {containerName}");
await containerClient.UploadBlobAsync($"{containerName}.zip", zipStream);
}
}
Have you found a mitigation/solution?
No
Comments
Is there any way I can get an OpenWrite stream to directly upload the zip stream into a container?
e.g:
From:
using (MemoryStream zipStream = new MemoryStream())
To:
using (MemoryStream zipStream = containerClient.OpenWrite())
or similar.
Amanda Nguyen commented
Hi Scott,
For v12 issues, please post them to the v12 repo
http://github.com/Azure/azure-sdk-for-net