I have successfully developed a webservice using springboot and angularjs to download an excel file from the server to my local machine. The URL is being generated correctly, however, I am encountering a 500 error. Below is the code snippet:
My Springboot class:
class MyWebserviceClass
{
@RequestMapping(method = RequestMethod.GET, value = "digital_data/{digital_file}", produces = "application/vnd.ms-excel")
public getExcelFileFromServer((HttpServletResponse response, @PathVariable("digital_file") String digital_file) throws IOException {
{
// download logic implementation would be here
}
AngularJS controller method
digitalService.getDigitalData(digital_file).then (function(res) {
var blob = new Blob([res.data], {type: "application/vnd.ms-excel"});
saveDigitalData(blob, digital_file);
}, function(errRes) {
$scope.showErrorMessage("Error");
})
};
AngularJS Service Layer
digitalService
{
function getDigitalData(digital_file) {
var url = 'digital_data/'+file_name;
return $http.get(url,{
transformRequest: angular.identity,
headers: {'Content-Type': undefined},
responseType:"arraybuffer"
});
}
}
Although the webservice URL is getting generated correctly, the issue lies in calling the springboot webservice.
Generated URL: http://localhost:8080/RMS/digital_data/user_review.xlsx
Error:
{resStatus: -3, appErrorMsg: "Could not find acceptable representation"}
Exception: com.media.MediaController.MyWebservice.getExcelFileFromServer(javax.servlet.http.HttpServletResponse,java.lang.String) throws java.io.IOException={[/digital_data/{digital_file}],methods=[GET],produces=[application/vnd.ms-excel]}}
If anyone could provide some assistance, as this is my first webservice project and I may have overlooked something. Apologies for any typing errors.