shruti garg
shruti garg

Reputation: 327

How to parse/download multiple files using spring boot post web service in angular 10

For consuming single file data return by the rest API, I have written below code in Angular,

  this._httpClient.post(getUrl,this.sampleGenerateRequestBody, {responseType: 'blob' })
    .subscribe((response: Blob) => {
     fileSaver.saveAs(response, "test" + '.csv')
   }
   );

But I am not able to download multiple files in case of multiple files are returned by the API. API response:

  --END
   Content-type: text/rtf
   Content-Disposition: attachment; filename=department10.txt

  empId=mm50478 empName=abc departmentid=10 status=1300 2020-11-11T13:19:00.896+05:30 
  empId=mm50479 empName=xyz departmentid=10 status=1300 2020-11-11T13:19:00.896+05:30

  --END
 Content-type: text/rtf
 Content-Disposition: attachment; filename=department3.txt

 empId=rk478 empName=rahul departmentid=3 status=1300 2020-11-11T13:19:00.896+05:30 
 empId=pg50479 empName=preeti departmentid=3 status=1300 2020-11-11T13:19:00.896+05:30
 
 
--END
--END--

Header:
vary:
Origin; Access-Control-Request-Method; Access-Control-Request-Headers
content-type:multipart/x-mixed-replace; boundary=END
transfer-encoding:chunked
date:Wed, 11 Nov 2020 07:49:02 GMT

 Here boundary is END. File content is segregated by this boundary.

I am not able to parse this response at angular side to put the content in two different files. If any one has any idea, how to do download multiple files?

Upvotes: 2

Views: 335

Answers (0)

Related Questions