Basically the user should be able to click on one link and download multiple pdf files. But the Catch is I cannot create files on server or anywhere. Everything has to be in mem
Below code is to get files from a directory in azure blob storage, merge in a zip and save it in azure blob storage again.
var outputStream = new MemoryStream();
var archive = new ZipArchive(outputStream, ZipArchiveMode.Create, true);
CloudBlobDirectory blobDirectory = appDataContainer.GetDirectoryReference(directory);
var blobs = blobDirectory.ListBlobs();
foreach (CloudBlockBlob blob in blobs)
{
var fileArchive = archive.CreateEntry(Path.GetFileName(blob.Name),CompressionLevel.Optimal);
MemoryStream blobStream = new MemoryStream();
if (blob.Exists())
{
blob.DownloadToStream(blobStream);
blobStream.Position = 0;
}
var open = fileArchive.Open();
blobStream.CopyTo(open);
blobStream.Flush();
open.Flush();
open.Close();
if (deleteBlobAfterUse)
{
blob.DeleteIfExists();
}
}
archive.Dispose();
CloudBlockBlob zipBlob = appDataContainer.GetBlockBlobReference(zipFile);
zipBlob.UploadFromStream(outputStream);
Need the namespaces: