504 Gateway Timeout Error While Downloading Folder with Multiple Files [closed]

19 hours ago 1
ARTICLE AD BOX

I am trying to download a folder that contains multiple files. However, when the number of files exceeds 40, a "504 Gateway Timeout" error occurs while using the current implementation.

Could you please assist in resolving this issue?

public string DownloadZip(string folderPath) { try { if (!Directory.Exists(folderPath)) return "ERROR: Folder not found"; string zipPath = Path.Combine(Path.GetTempPath(), "SPLDownload_" + Guid.NewGuid() + ".zip"); using (FileStream fsOut = System.IO.File.Create(zipPath)) using (ICSharpCode.SharpZipLib.Zip.ZipOutputStream zipStream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(fsOut)) { zipStream.SetLevel(3); var files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories); foreach (string file in files) { string entryName = file.Substring(folderPath.Length).TrimStart('\\'); var entry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(entryName) { DateTime = DateTime.Now, Size = new FileInfo(file).Length }; zipStream.PutNextEntry(entry); byte[] buffer = new byte[4096]; using (FileStream fs = System.IO.File.OpenRead(file)) { int bytesRead; while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0) { zipStream.Write(buffer, 0, bytesRead); } } zipStream.CloseEntry(); } zipStream.Finish(); } return zipPath; // ✅ return zip file path } catch (Exception ex) { return "ERROR: " + ex.Message; } }
Read Entire Article