0

Having the following server response

cache-control: no-cacheno-storemax-age=0must-revalidate
connection: keep-alive
content-disposition: attachment; filename="filename.bpmn.xml"
content-encoding: gzip
content-type: application/xml
date: Tue24 Nov 2020 02:35:02 GMT
expires: 0
keep-alive: timeout=60
pragma: no-cache
transfer-encoding: chunked
vary: accept-encoding,origin,access-control-request-headers,access-control-request-method,accept-encoding 
x-content-type-options: nosniff
x-frame-options: DENY
x-xss-protection: 1; mode=block 

How can I get the content of the file to download from the response body?

I get this header by inspecting the response header of an endpoint in swagger

Right now when trying the next action

fetch(basename: string): Observable<any> {
  return this.httpClient.get(ApiEndpoints.ENTRY, {
    headers: new HttpHeaders({
      'Access-Control-Expose-Headers': 'Content-Disposition',
      'Content-Disposition': 'attachment',
      'Content-Type': 'application/xml',
      Accept: 'application/xml'
    }),
    params: new HttpParams().set('object', basename)
  });
}

Get the following error

net::ERR_CONTENT_DECODING_FAILED 200 (OK)

Along with the following error message

Http failure response for /api/bpm/download: 0 Unknown Error

Update 0

Error object

enter image description here

Update 1

In the following example I share the result that returns when testing in Swagger. In case there is any indication that I overlook.

Highlighted is the file that returns when calling the endpoint. And from which I need to get its content

enter image description here

Thanks for your comments

Mario
  • 4,784
  • 3
  • 34
  • 50
  • Instead of `'Content-Type': 'application/xml'`, use `'Accept': 'application/xml'`, since you want to receive the xml content. – Sambit Nov 24 '20 at 04:35
  • Thanks for answering, unfortunately the error message persists. `net::ERR_CONTENT_DECODING_FAILED 200 (OK)` I have updated the question to show the full error object – Mario Nov 24 '20 at 04:41
  • The file content can be downloaded as multipart content or as base64 encoded from the response xml file. – Sambit Nov 24 '20 at 04:55
  • Could you please provide an example of how to set these headers properly – Mario Nov 24 '20 at 04:59
  • Check this. https://stackoverflow.com/questions/52154874/angular-6-downloading-file-from-rest-api – Sambit Nov 24 '20 at 05:10

0 Answers0