Monday 28 January 2019

How to get interim response in Angular HTTP - ArrayBuffer

I'm having a Electron application internally I'm loading the Angular application. I'm downloading a byte array (i.e., ArrayBuffer) through an API call and passing those data to a method which I'm connecting through electron.remote.require('./file-service') to create a file in a local file system.

If the User changes the route, a popup window will prompt to get the confirmation of navigation. If the User clicks ok and the http request is in between, I need to store the received bytes.

Sample Angular Code:

declare var electron: any;
const { createDataFile } = electron.remote.require('./file-service')

const payLoad = new FormData();
const httpOptions =  {
      headers: new HttpHeaders(),
      reportProgress: true,
    };

const req = new HttpRequest('GET', 'http://localhost:8080/getData', payLoad, {...httpOptions, responseType: 'arraybuffer'});
this.http.request<ArrayBuffer>(req).subscribe((event: HttpEvent<ArrayBuffer>) => {

    switch (event.type) {
        case HttpEventType.DownloadProgress:
            // This method will manipulate and show the progress bar in the UI
            this.updateProgress(event.loaded);
        break;
        case HttpEventType.Response:
            createDataFile(event.body)
        break;
    }

});

I'm trying to save data, If the arraybuffer size is 25MB and I received 12MB and I'm trying to navigate away, in that moment I need to store that 12MB. Kindly assist me how to get the interim response.



from How to get interim response in Angular HTTP - ArrayBuffer

No comments:

Post a Comment