User1793652459 posted
Hello,
I am trying to learn to use this example to upload files to a folder with angularjs.
http://www.encodedna.com/angularjs/tutorial/angularjs-file-upload-using-http-post-formdata-webapi.htm
I created a Web application in VS 2015. Added the C# controller code, js and HTML code as shown in this example in HTML, created a folder for files in the app called locker but when I run my app attach a file and click on the upload button nothing happens.
It doesn't run the upload function in the API to to copy files. I have verified when I click on the Upload button it hits my alert code but not sure why not the url to the api. I guess I am not getting the step to make it route to the /api/fileupload
so function can run. Here is the code that button is supposed to run:
// NOW UPLOAD THE FILES.
$scope.uploadFiles = function () {
alert('gets here')
var request = {
method: 'POST',
url: '/api/fileupload/',
data: formdata,
headers: {
'Content-Type': undefined
}
};
// SEND THE FILES.
$http(request)
.success(function (d) {
alert(d);
})
.error(function () {
});
}
The only other thing I did was to change the name of the controller in my RouteConfig.cs from :
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
to
defaults: new { controller = "FileUpload", action = "Index", id = UrlParameter.Optional }
Is there another step I am missing?
Thanks