We are storing our files into Azure blob, we are giving option to our user to download multiple files in a zip format ( can be 500-1000 files) from our website. We have placed a code but its taking longer time to execute and as we are having our website hosted on Azure Web app its getting 500 request time out. Can some one help us to show how we can improve and make it more faster?
Please find a code that we did.
string[] pods;
string fileName = "";
try
{
System.IO.Directory.CreateDirectory(path);
foreach (var item in objData)
{
pods = item.POD.Split(new string[] { "," }, StringSplitOptions.None);
foreach (var itemPOD in pods)
{
string[] data = itemPOD.Split(new string[] { "/" }, StringSplitOptions.None);
fileName = System.IO.Path.Combine(path, DateTime.Now.ToString("dd_MM_yyyy") + "_" + data[data.Length - 1]);
try
{
var stream = new WebClient().OpenRead(itemPOD);
using (System.Drawing.Image img = System.Drawing.Image.FromStream(stream))
{
img.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg);
GC.Collect();
}
}
catch (Exception)
{
}
}
}
FileDownloads objFileDownload = new FileDownloads();
var filesCol = objFileDownload.GetFile(path);
using (var memoryStream = new MemoryStream())
{
using (var ziparchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
{
for (int i = 0; i < filesCol.Count; i++)
{
ziparchive.CreateEntryFromFile(filesCol[i].FilePath, filesCol[i].FileName);
}
}
return File(memoryStream.ToArray(), "application/zip", "Attachments.zip");
}
}
catch (Exception)
{
}