I use angularjs in my project.
I laod file with extension .xlsx and I need to post it to the web services and two integers numbers, month and year.
Here is HTML:
<div class="col-xs-5">
<label class="btn btn-success btn-sm">
Load File <input type="file" id="inptFile" onchange="$('#upload-file-info').html(this.files[0].name)" hidden>
</label>
<span class='label label-default' id="upload-file-info">. . .</span>
</div>
Here is javascript code that fired after the file is loaded:
$scope.loadFile = function () {
if (hasExtension('inptFile', ['.xlsx']))
{
var file = $('#inptFile')[0].files[0]; //get the file
//here post file to service.
}
else {}
}
function hasExtension(inputID, exts) {
var fileName = document.getElementById(inputID).value;
return (new RegExp('(' + exts.join('|').replace(/\./g, '\\.') + ')$')).test(fileName);
}
And here is web service:
[WebMethod]
public List<DepartmentReport> SaveXml(int year, int month, file)
{
//some logic
}
After I get the file(after this row) var file = $('#inptFile')[0].files[0] I need to post file, year and month to web service.
How can I post two integers and file to the web service above using angularjs $http post?