1
<input type="file" ng-model="ch.FileName" id="file" name="myFile" nchange="angular.element(this).scope().saveChapter(this.files)"/>
                

Action Method,Js and other Code

1
  • Thanks for your first contribution. To improve this question, please read How to Ask and minimal reproducible example - then edit your question. Show what you got, what you aim for, and what you get and make clear what your problem is. Commented Jul 9, 2021 at 16:22

1 Answer 1

1

Upload File and Data with Angularjs in MVC .net core

If you'd like to post binary data with other additional information/data from your angularjs frontend to WebAPI backend, you can try to pass the data through FormData object, like below.

var formdata = new FormData();
formdata.append('chapterID', $scope.ch.ChapterID);
formdata.append('bookID', $scope.ch.BookID);
formdata.append('chapterName', $scope.ch.FileName);
//...
formdata.append('cHFile', $scope.chfile);

$http({
    method: 'POST',
    url: 'your_request_url_here',
    headers: { 'Content-Type': undefined },
    data: formdata
}).then(function mySuccess(response) {
    //...

In browser developer tool Network tab, can find the data passed as expected

enter image description here

Test Result

enter image description here

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

Comments

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.