I am trying to read excel file to save the records inside the file into database.
Below is my html code :
<div ng-controller = "myCtrl">
<input type="file" file-model="myFile"/>
<button ng-click="uploadFile()">upload me</button>
</div>
I am using this Javascript code to read the file :
$scope.uploadFile = function(){
var file = $scope.myFile;
console.log('file is ' );
console.dir(file);
$http({
method : "POST",
url : "/Example/fileUpload",
data : file
}).then(function mySuccess(response) {
console.log(response);
}, function myError(response) {
console.log(response);
});
};
Also, the java code I have written to handle this is :
@RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<String> checkTestMapping(@RequestBody Object file){
System.out.println(file);
return null;
}
It is giving me the following error after I select a file (excel file) and click upload.
error: "Unsupported Media Type" message: "Content type 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8' not supported" path: "/Example/fileUpload" status: 415 timestamp: "2018-06-14T17:11:27.494+0000"
Can someone help me with this ?