I am using ionic5 with Angular. My API returns pdf as Blob object. I am able to get Blob response when using Angular Http(which works on browser)
let headers =
new HttpHeaders({
'Accept': 'application/pdf',
'Content-type': 'application/json',
'Authorization': 'Bearer token',
'Access-Control-Allow-Origin': 'localhost'
});
return this.httpClient.post(
apiURL,
JSON.stringify(myBodyParamsObj),
{headers: headers, responseType: 'blob'}
);
But I am not able to get response when using ionic native http(which is required to use to run app in device due to CORS issue when using Angular Http). Tried like below-
this.nativeHttp.setDataSerializer("raw"); // Tried other options like json etc. but none works
this.nativeHttp.post(apiURL, params, { 'Authorization': myAuthHeaderObj, 'Content-Type': 'application/json', 'Accept': 'application/pdf', responseType: 'blob'});
Also tried this.nativeHttp.sendRequest
but didn't get success.
Please help
Finally it worked using below piece of code-
So basically , instead of using nativeHttp.post, nativeHttp.sendRequest() willwork as it accepts responseType='blob'