I got this problem:
I made a REST application, that creates a file from the data I send from the controller.
I save the file on the server, and enable the client to download it.
The code looks like this:
myAppFactory.exportData($scope.userId, $scope.selectedUserScript.scriptId, $scope.selectedUserPatient.patientId,
$scope.sDateMillis, $scope.eDateMillis, $scope.exportObject).success(function(data) {
window.location = "rest/pName/download/" + $scope.userId + "/" + data;
// deleteFile(data);
});
}
I call my factory from the service, to create the file, and after it's done, the line:
window.location = ...
The browser automatically enables me to download the file. It opens the save dialog to the download folder(of the client).
That works just fine, but here is my problem. After I download the specific file from the server, I need to delete it.
I made the function:
deleteFile = function(data) {
myAppFactory.deleteFileFromDSS($scope.userId, data).success(function(data) {
console.log("delete:" + data);
})
}
And on the server side all the function have their implementations, BUT, my problem is, since it's an asynchronous call from the angularJS, the function delete is often called before the download even starts.
So I tried to get some response from the window.location function, but I simply cannot figure it out.
So I what I need is: Somehow to get the response from when the SAVE button is clicked and the download process is completed, and with an if statement get the job done
I hope you got my problem, pls help.