I am writing a simple service that uploads a file and posts it to a Spring controller. The controller manipulates this data and returns several objects as JSON. I am working wit
Its very easy.
fileUpload.uploadFileToUrl (file,uploadUrl, {
successCallBack: yourSuccessHandler,
failureCallBack: yourFailureHandler
});
function yourSuccessHandler(data) {
$scope.data= data;
}
function yourFailureHandler() {
console.log("Failed Messge printing from Controller");
}
myApp.service('fileUpload', [ '$http', function($http) {
this.uploadFileToUrl = function(file, uploadUrl, options) {
var fd = new FormData();
fd.append('file', file);
$http.post(uploadUrl, fd, {
transformRequest : angular.identity,
headers : {
'Content-Type' : undefined
}
})
.success(function(data) {
console.log("upload successful");
if(options && options.successCallBack) {
return options.successCallBack(data);
}
})
.error(function() {
console.log("upload error");
if(options && options.failureCallBack) {
return options.failureCallBack();
}
});
}
} ]);