1

I'm not getting any callback to the success/fail handlers on my Angular $http.post call. My server side is .NET MVC controller; the controller is getting the file and works properly there, I've debugged through it, so the POST call itself seems to be working fine. There just isn't a callback on the client javascript side.

I've a basic scope function ...

$scope.uploadFile = function(files) {
    var fd = new FormData();
    fd.append("file", files[0]);

    $http.post('api/clubs/upload', fd, {
        withCredentials: true,
        headers: {'Content-Type': undefined },
        transformRequest: angular.identity
    })
        .then(function (response) {
            alert("Success:" + result.status);
        }, function (response) {
            alert("Failuer: " + result.status);
        });
};

Neither of the alerts are popping up.

Server side controller is ...

string root = HttpContext.Current.Server.MapPath("~/Upload_Data");
        var provider = new MultipartFormDataStreamProvider(root);

        try
        {
            // Read the form data.
            await Request.Content.ReadAsMultipartAsync(provider);

            // This illustrates how to get the file names.
            foreach (MultipartFileData file in provider.FileData)
            {
                Trace.WriteLine(file.Headers.ContentDisposition.FileName);
                Trace.WriteLine("Server file path: " + file.LocalFileName);
            }


            // Show all the key-value pairs.
            foreach (var key in provider.FormData.AllKeys)
            {
                foreach (var val in provider.FormData.GetValues(key))
                {
                    Trace.WriteLine(string.Format("{0}: {1}", key, val));
                }
            }


            return Request.CreateResponse(HttpStatusCode.OK);
        }
        catch (System.Exception e)
        {
            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
        }

The file is getting uploaded and stored in the "Upload_Data" folder.

Why no callback on the client side?

0

1 Answer 1

1

in scope you're calling result.status but your parameter name is response .Fix the name and try maybe there is a syntax error.

Sign up to request clarification or add additional context in comments.

1 Comment

ha! Thanks for the extra set of eyes, kyur. That was the (dumb) issue. Working now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.