I am faced with managing the HTTP GET response from a Java Spring GET request. The file downloaded from the server is in zip format, containing a .pdf and .png file. Below is the Java code snippet:
@RequestMapping(value="/data/{meetingId}", method = RequestMethod.GET)
public byte[] getMeetingRest(@PathVariable(value="meetingId") String meetingId) {
byte[] file = new byte[1024];
Buffer buf =null;
try {
String url = getContentServer()+"/data?username="+getUsername()+"&password="+getPassword()+"&id="+meetingId;
RestTemplate templ = new RestTemplate();
file = templ.getForObject(url, byte[].class);
} catch (Exception e) {
String msg = "Error retrieving meeting list";
logger.error(msg, e);
}
logger.info("file zip --> "+file.length);
return file;
}
And this is the Angular HTTP GET request:
appControllers.controller('FolderListController', ['$scope', '$routeParams', '$http', '$timeout', '$q', 'global',
function($scope, $routeParams, $http, $timeout, $q, global){
console.log("FolderListController");
var meetingId = $routeParams.meetingId;
$http.get(CONTEXT_PATH+"/services/data/"+meetingId, {responseType: 'arraybuffer'})
.success(function(data){
console.log(data.length);
console.log(data);
})
.error(function(e){
console.log("Errore chiamate rest data zip e = "+e);
});
//Displaying the correct items.
for(var i=0;i<global.meetings.length;i++){
console.log("meetingList["+i+"] = "+global.meetings[i]);
if(global.meetings[i].id == meetingId){
console.log("Found id : id="+global.meetings[i].id+" -- meetingId = "+meetingId);
$scope.items = global.meetings[i];
break;
}
}
}]);
The output is as follows:
undefined controllers.js:108 ArrayBuffer {}.
Any helpful advice or suggestions would be greatly appreciated. Thank you.