I have a simple use case as below -
User triggers a REST API call to process file upload
The file gets uploaded on cloud at back end
The API returns a response with URL for downloading the file like - http://somedomain/fileName.zip 
After file gets downloaded at Client side , there is another API call to update DOWNLOAD count in database for the downloaded file
This is being achieved using Angular code at client side . 
The pseudo code for this is as below :
//Download Service Call to Download File . It returns Obseravable 
downloadService.downloadFile.subscribe(
(data: downloadData) => processDataDownload(data);
(err) => this.message = "Error Downloading File ";
);
//method processing file download and updating download count 
private processDataDownload(data : Response){
   this.downloadFile(data);
   this.updateDownloadCount(data);
}
//download a file using URL 
private downloadFile(data : Response) : void {
   //standard java script code to get file download using URL click     
    var a = document.createElement("a");
    a.href = data.downloadUrl;
    fileName = data.downloadUrl.split("/").pop();
    a.download = fileName;
    document.body.appendChild(a);
    a.click();
    window.URL.revokeObjectURL(url);
    a.remove();
}
//update download count 
private updateDownloadCount(data : Response ){
    //another http call to update download count for files 
}
Now , my question is :
1)Is there any way we can make updateDownloadCount method gets called ONLY after the file gets DOWNLOADED successfully ?
2)Meaning , the java script code in method - downloadFile , triggers a file download using programmatic URL click 
3)Can we wait for this download happen and then call updateDownloadCount ? 
4)Can we wait for DOWNLOAD event completion and then trigger database update ? 
5)Is there any way we can achieve this ?
 
    