4
votes

I am using valums fileuploader in asp.net web application. It's working fine with the actual uploads as such. But the error condition checking is not working properly in Chrome and FF. The uploader points to a handler called fileupload.ashx which checks if a file with the same name already exists. The c# code is given below ...

if (File.Exists(Path.Combine(path, fileName)))
{
    returnJson = "{success:false, error:'Duplicate filename'}";
    context.Response.ContentType = "text/plain";
    context.Response.Write(returnJson);
    return;
}

I expected above error message in result.error property. After some javascript debugging, I found that this code works well for IE8 but not in Chrome and FF. The xhr responseText contains null string when the transfer fails.

The javascript snippet from valums fileuploader.js is given below ...

xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
        self._onComplete(id, xhr);
    }
};

Surprisingly, responseText is properly returned even in Chrome and FF when the upload succeeds. Any help will be greatly appreciated.

1
Assuming that you want to upload Single file at a time the AsyncFileUpload control in the Ajax Control Toolkit can be a useful altenative for ASP.Net.Pankaj Kumar

1 Answers

0
votes

I'm not quite sure why the fileupload.ashx has this code in it ...

context.Response.ContentType = "text/plain";

this should be ...

context.Response.ContentType = "application/json";

since the return value is of type JSON.

hope this helps.