I have created a Web API method to download a blob file from azure storage and its working fine and I have written the code to download only one file, but I want to download many blob files as a zip file from Azure Blob Storage.
So my question here is simple that How to convert or make a zip file from memory stream? And I looped and got a memory stream List like below, but I don't know how to append this list to Zip and return as an HttpResponseMessage, Could anybody please help me to append multiple Memorystream to a zip file?
And please find the following methods that I have written for download a blob file from Azure.
API Method,
{
var document = DataContext.Documents.FirstOrDefault(d => d.DocumentId ==
documentId && d.IsActive `enter code here`);
//azure storage connection
CloudBlockBlob blob = GetBlobReferece(document);
MemoryStream memStream = new MemoryStream();
//downloads the memory stream of a
await blob.DownloadToStreamAsync(memStream);
HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
httpResponseMessage.Content = new ByteArrayContent(memStream.ToArray());
httpResponseMessage.Content.Headers.Add("x-filename", document.FileName);
httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
httpResponseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
httpResponseMessage.Content.Headers.ContentDisposition.FileName = document.FileName;
httpResponseMessage.StatusCode = HttpStatusCode.OK;
return httpResponseMessage;
}
Tried for Multiple Blob Files,
List<MemoryStream> memStList = new List<MemoryStream>();
for (int i = 1; i <= 3; i++)
{
CloudBlockBlob b = GetBlobReferece(documentList[i - 1]);
MemoryStream ms = new MemoryStream();
b.DownloadToStreamAsync(ms);
memStList.Add(ms);
}