0
Hello, I’m having trouble downloading a file generated by backend in my angular project, I have the following method
generateXlsx(obj) {
let headers = new Headers();
let token = localStorage.getItem('token');
let client = localStorage.getItem('client');
let uid = localStorage.getItem('uid');
headers.append('access-token', token);
headers.append('client', client);
headers.append('uid', uid);
return this.http.get(this.xlsxUrl, { params: obj, headers: headers });
}
When it is called it goes to Download url of my file, but when I call this Route/Url via angular, it does not download, but in the Network tab the file is saved in Answer, follow print of the result
In my Frontend, when I press a button and call the following method
generatePlanilha(obj) {
this.api.generateXlsx(obj)
.subscribe(response => {
if (response) {
console.log("Planilha Gerada");
}
},
(error => { console.log("NAO GEROU PLANILJA") }));
}
I was wondering how I do to download the answer that is on the Network
This gives the following error in "[Response]" [ts] Type 'Response' is not Assignable to type 'Blobpart'. Type 'Response' is not Assignable to type 'Blob'. Property 'size' is Missing in type 'Response'. [2322] (Parameter) Answer: Response
– Marcelo Henrique Dos Reis
Try this modification I made,
.map((res:Response) => res.text())
– edson alves
now the parameters of the . map gave the following error: [ts] Argument of type '(res: Response) => Promise<string>' is not Assignable to Parameter of type '(value: Response, index: number) => Promise<string>'. Types of Parameters 'res' and 'value' are incompatible. Type 'import("/home/Marcelo/Desktop/Mercatorio/Dashboard/node_modules/@angular/http/src/static_response"). Response' is not Assignable to type 'Response'. Property 'redirected' is Missing in type 'Response'. [2345]
– Marcelo Henrique Dos Reis
What version of angular? May have some change in the import of
map
, try like this :import { map } from "rxjs/operators";
– edson alves
Angular CLI: 7.0.4 Node: 8.12.0 OS: linux x64 Angular: 5.1.2, I’ve already imported the map
– Marcelo Henrique Dos Reis
It should work, it seems that the Sponse that imported
import("/home/marcelo/Desktop/Mercatorio/dashboard/node_modules/@angular/http/src/static_response")
is not correct, tries to remove this import and leave the type asany
– edson alves
the permance error: [ts] Argument of type '(res: Response) => Promise<string>' is not Assignable to Parameter of type '(value: Response, index: number) => Promise<string>'. Types of Parameters 'res' and 'value' are incompatible. Type 'import("/home/Marcelo/Desktop/Mercatorio/Dashboard/node_modules/@angular/http/src/static_response"). Response' is not Assignable to type 'Response'. Property 'redirected' is Missing in type 'Response'. [2345] interface Response
– Marcelo Henrique Dos Reis
Some light to give me?
– Marcelo Henrique Dos Reis
Let’s go continue this discussion in chat.
– edson alves
I called you in the chat room.
– Marcelo Henrique Dos Reis