I have an application that calls an api that returns files and compresses them into a zip file.
I have created my own service and it works perfectly.
return this.http.get(this.rootUrl + '/api/Files/DownloadFile?files=' + fileSelected + '&user=' + user, { responseType: 'blob' as 'json' }); // working ok
Here the api response is a blob object as it must be.
But when I try to do the same thing using a swagger generated service, it doesn't work anymore.
let req = new HttpRequest<any>(
'GET',
this.rootUrl + `/api/Files/DownloadFile`,
__body,
{
headers: __headers,
params: __params,
responseType: 'text'
}
); // not working ok
The service returns me null, however in chrome inspector, in the response to the api call, it shows strange characters.
this.filesService.DownloadFile({"files": ids, "user": this.user}).subscribe(
data => {
console.log(data); // data value is null but in the response I see strange characters
},
err => {
console.log(err);
}
);
This is normal, because the responseType of the swagger service is "text", I have tried to manually change the contentType to "blob" (swagger specifications) or "blob as json" (angular 5), but it didn't working ok.
Is it possible to solve it from Angular using the service generated by swagger or do I have to touch the API? Thank you