Question

I've got an ASP.NET web application (utilizing WebForms) and am using Uploadify to handle uploading large files. This is done by posting the file to an HttpHandler.

Example of code (simplified for demonstration purposes):

$(".uploadify").uploadify({
    'uploader': '/uploadify/uploadify.swf',
    'script': 'SaveUploadedFile.ashx',
    'cancelImg': '/uploadify/cancel.png',
    'queueID': 'fileQueue',
    'auto': true,
    'multi': false,
    'method': 'post',
    onSelect: function(e, queueId, file) {
        alert(file.name + " selected");
    },
    onComplete: function(e, queueId, file, response, data) {
        alert("complete: " + response);
    },
    onCancel: function(e, queueId, file, data) {
        alert("cancel");
    }
});

The HttpHandler that receives the file is fairly simple:

public void ProcessRequest(HttpContext context)
{
    Debug.WriteLine("Save file");

    if (context.Request.Files.Count == 0)
        throw new SystemException("No files uploaded");

    // Get the file
    HttpPostedFile file = context.Request.Files.Get(0);
    Debug.WriteLine("Got file: " + file.FileName + ", Length: " + file.ContentLength);

    // Save it
    string guid = Guid.NewGuid().ToString();
    string path = Path.Combine(Path.GetTempPath(), guid + ".tmp");
    file.SaveAs(path);
    Debug.WriteLine("Saved to path: " + path);

    // Update response and return guid
    context.Response.StatusCode = 200;
    context.Response.Write(guid);

    Debug.WriteLine("All Done");
}

The problem is that the progress bar being displayed doesn't actually reflect the progress of the upload, and shows the upload as being complete long before the file is actually uploaded. Therefore, the user interface effectively appears like it is doing nothing while the progress bar stays at 100%, until the file is complete.

In some cases, the upload simply fails after reaching 100%, with the OnComplete event never getting fired, almost like the response from the HttpHandler is getting lost in transit, even though the file is saved.

I've tried both Flajaxian and SWFUpload, and experienced similar issues with the progress bar being completely out of sync with actual upload progress, indicating completion well before the upload was actually complete.

This problem is not apparent when testing locally, or with small files (typically under a few megabytes) as these tend to upload fairly quickly and there's little or no lag between the file being uploaded and the progress bar completing.

Is there any way of using a Flash upload solution (such as Uploadify) with an ASP.NET web application and have the progress bar better represent the actual progress of the upload?

Update: Eventually, I gave up trying to use a flash based uploader as they seemed a bit too awkward, especially the progress bar, which didn't represent the actual progress of the upload at all. Replaced this with Brettle NeatUpload instead which works much better.

Was it helpful?

Solution

This could be an issue with your anti-virus software (specifically AVG) and its upload proxy or firewall. Here's a related issue:

Every flash uploader giving bad progress values

OTHER TIPS

Your problem seems to be a common one. I would give http://www.swfupload.org/ a try.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top