0

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.

Elydasian
  • 2,016
  • 5
  • 23
  • 41
  • if you want to create a file you can do that in browser it self. why you are creating file in server and then you are deleting? check this one https://stackoverflow.com/questions/3665115/create-a-file-in-memory-for-user-to-download-not-through-server – Dinesh undefined Jul 21 '17 at 07:20
  • because I dont have all I need in the controller, because I make an XLSX file with tables and charts and so on.....And i need to delete it because I dont want to fill my server with trash files that I dont use – Elydasian Jul 21 '17 at 07:33
  • I don't think you can track the progress of a downloading file on browsers. I suggest you to create a schedule like Garbage Collector to remove the downloaded file – huydq5000 Jul 21 '17 at 08:10
  • ... mby there is some trick to it? I mean, how is it possible that something like that can not be tracked? – Elydasian Jul 21 '17 at 08:24

0 Answers0