This is a migrated thread and some comments may be shown as answers.

How to fail an Upload save handler?

0 Answers 119 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Shimshon
Top achievements
Rank 1
Shimshon asked on 14 Oct 2012, 04:08 PM
Hello,
I'm uploading a CSV file and try to parse it.
I want to return to the client a responsive message what is the issue (as I found it).

I've tried this:
Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;
Response.ContentEncoding = Encoding.UTF8;
            Response.ContentType = "application/json; charset=utf-8";
            

return Json(myResponse, Response.ContentType, Response.ContentEncoding);

Where myResponse is of a specific type containing my status code. I'm checking the value of my Status Code (called Rc) and act accordingly. 

I'm changing the StatusCode, because the retry button appears and the user can try uploading again easily).
It work fine in Chrome and FF, but not in IE (all in my dev server)
I've change the behavior to be like this:

// for IE responseText
if (Request.Browser.IsBrowser("IE"))
{
     Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
     Response.ContentType = "text/html; charset=utf-8";
}
// End of

and that solve the issue for IE.

BUT:
When moved to testing environment, the myResponse is holding the 'BadRequest' string and not my Json response, and then I don't have any info to display to the client.

So - I've removed the line 
Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest;

and my js handler look like that
function onUploadSuccess(e) {
            //alert("Success (" + e.operation + ") :: " + getFileInfo(e));
 
            if (e.response.Rc != 'OK')
                addFileRow(e.files[0].name, e.response.ErrorMessages, e.response.CurrentTime, "uploadRowError""");
            else {
                var runCmd = "<div .... />";
                addFileRow(e.files[0].name, e.response.ErrorMessages, e.response.CurrentTime, "uploadRowSuccess", runCmd);
            }
        }
And the question: Can I mark the operation as failed in the onSuccess handler ? Thanks Shimshon

No answers yet. Maybe you can help?

Tags
Upload
Asked by
Shimshon
Top achievements
Rank 1
Share this question
or