0

I'm trying to upload a file via angular.

So far I can select the file and post it from the angular end but I can't get the controller to receive the file.

this is how I post the file:

var f = new FormData();
f.append("file", file);

$http.post("/LoadFile", f); 

but I can't seem to get my controller to receive the file. I've tried all the following:

[HttpPost]
public ActionResult Upload(object file)

[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)

[HttpPost]
public ActionResult Upload(HttpRequestMessage request)

[HttpPost]
public ActionResult Upload()

If I add breakpoint to the methods the only one that gets hit is the last one.

Sun
  • 4,458
  • 14
  • 66
  • 108
  • Please See This https://stackoverflow.com/questions/33730489/how-to-upload-a-file-in-restangularjs-using-multipart-formdata/33751217#33751217 – Rohan Kawade Jun 23 '17 at 08:06

1 Answers1

1

Sorted.

I just needed to add the following the post method:

$http.post("/LoadFile", f, {
                transformRequest: angular.identity,
                headers: { 'Content-Type': undefined }
            }); 
Sun
  • 4,458
  • 14
  • 66
  • 108