在服务器上压缩文件时出现问题

问题描述:

我的网站上有图像,用户可以在其中下载所选图像.当用户选择多个图像时,这些文件将以zip文件的形式下载;压缩过程在服务器上进行.

但是,当用户选择更多文件时(文件大小也增加了50MB),因此当他按下下载时,将在服务器上开始压缩.网页正在挂起,在压缩过程完成之前,用户无法执行任何操作.

有时,浏览器(例如Chrome)会显示消息(过程耗时太长,请终止该过程).所以我正在这里寻求帮助.

我需要一个扎实的建议:)

谢谢

I have images on my website where the user can download selected images. When the user selects more than one image the files are downloaded as zip files; the zipping process takes place on the server.

However, when the user selects more files( the size also increase let say by 50MB) so when he presses download the zipping starts on server. The web page is hanging and the user can''t do anything until the zipping process has completed.

Sometimes the browser (like Chrome) gives messages (process is taking too long , kill this process). So I am looking for some help here.

I need a solid suggestion :)

Thanks

^ ]会给您一个想法.

顺便说一句,如果您发布了代码,我们的专家可以浏览一下并提供反馈.
This[^] will give you an idea.

Btw if you posted your code, our experts can glance it, and give the feedback.


您好,

您可以使用Web配置来增加httpruntime.
在Web配置中使用此..
Hi,

You can increase httpruntime using web confige.
In web confige use this ..
<httpRuntime executionTimeout="90" maxRequestLength="2097151" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/>




或者另一件事是您可以使用自己的exe在后台执行所有操作.当文件大小超过50mb时,会告诉用户自动邮件将向您发送文件.您必须在服务器上启动执行所有压缩过程的exe并将邮件发送给用户.




Or another thing is you can use your own exe that do this all thing in background. when file size is more than 50mb than tell user that an automatic mail will send you will file. you have to start your exe on server that do all zipping process and send mail to user.


使用7Zip命令行工具可以在服务器中压缩文件或文件夹.
您可以从此处 [
Using 7Zip command line tool you can Zip file or folders in server.
you can download 7Zip command line tool from Here[^]

check the sample code to zip a folder


protected void ZipFolder_Click()
   {
       ProcessStartInfo p = new ProcessStartInfo();
       string sourceName = Server.MapPath("test");
       string targetName = Guid.NewGuid().ToString();
       p.FileName = Server.MapPath("7za.exe");
       string ZipCommand = string.Format(@" a -tzip {0}.zip {1}\*", targetName, sourceName);
       p.Arguments = ZipCommand;
       p.WindowStyle = ProcessWindowStyle.Hidden;
       p.UseShellExecute = false;
       Process x = Process.Start(p);
       String errmsg = "";
       while (!x.StandardOutput.EndOfStream)
       {
           errmsg += x.StandardOutput.ReadLine() + "<br />" + Environment.NewLine;
       }
       Response.Write(errmsg);
       x.WaitForExit();
   }




如果您想了解更多信息,请检查
7-Zip命令行示例 [ .NET 7压缩可执行教程 [




if you want to know more check
7-Zip Command-Line Examples[^]
.NET 7-Zip Executable Tutorial[^]