1

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 500MB) 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

my code for zipping the file is:

public string Zip(string f, bool original)
{

    string zip = "";
    try
    {
        files = HttpContext.Current.Server.UrlDecode(files);
        string[] fileCollection = files.Split('*');
        zipFile = class1.zipfile(fileCollection, IsOriginal);


        int fileLength = files.Length;
    }

    catch (Exception ex)
    {
        Console.WriteLine("Exception during processing {0}", ex);


    }
    return File;
safi
  • 3,636
  • 8
  • 24
  • 37

2 Answers2

2

Three suggestions:

  1. Show a busy screen on the client that lets the user know that he's waiting for a file download. You could achieve this i.e. by downloading to a separate iframe and checking the status of the iframe (for a dynamic approach see Dynamically created iframe used to download file triggers onload with firebug but not without)
  2. Check how you actually zip the files - is compression required or do you just want to download all pictures together? Zipping with no compression is usually much faster.
  3. If it still takes too long - even for a busy screen - consider using an asynchronous approach: A user may request a zip file with the images he/she selected, which causes the system to start processing the zip file. The user then may wait or come back to a dedicated page to check on the status of the zip file and, if it's ready, download it immediately from the server (i.e. from a virtual directory you put it after processing). This approach is a little more involved, also you have to think about cleanup.
Community
  • 1
  • 1
BrokenGlass
  • 158,293
  • 28
  • 286
  • 335
  • @ broken Glass: for your suggestion number 2, I am using no compression. for suggestion number 1: I am using XSLT, AJAX, so you think that is good using your first suggestion? – safi Feb 04 '11 at 14:32
  • @ Broken Glass: i have already done the clean up script for the file that are being zipped and downloaded, but now i am thinking about this asynchronous approach, dont you think if a user press download, so a new small window opens, and show him progress bar, that show him the progress for zipping up the files? – safi Feb 04 '11 at 14:43
  • i cannot figure it out, can any one help me out? – safi Feb 07 '11 at 14:18
2

I would split off the zipping to a separate process (BackgroundWorker process?) and then update a status bar (AJAX) to keep the user informed of approximately how long it's going to take.

Kendrick
  • 3,747
  • 1
  • 23
  • 41
  • @safi, thinking about it, it may not be required. I think @BrokenGlass has an excellent solution in using an iframe for status. You may be able to set a session variable and read from that in the iframe that is doing the status updates. – Kendrick Feb 04 '11 at 14:37
  • @ Kendrick: I am waiting for that backgroundworker process. should i post the jcript also? – safi Feb 04 '11 at 14:47
  • i HAVE TO USE the background worker and cute web ui progress bar. – safi Feb 04 '11 at 15:34
  • Do you have access to modify the class1.zipFile function? If so, you may be able to spawn a second thread in there and report progress back. The issue with reporting progress with a BackgroundWorker thread is that you have to report the status from within the BackgroundWorker.DoWork event handler. If you can add files to the .zip one at a time, and fire off a ProgressChanged event after each file is added, you're good to go. If you can only send a list of files to the library, then you have an issue, no matter which method you'd like to use. That is why I like @BrokenGlass's options best. – Kendrick Feb 05 '11 at 17:43