Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

314
Views
Cómo descargar excel en respuesta desde api react.js

Mi API responde como esta demostración [URL][https://mytutari.com/webservices/contract/exportcallnote/10377431] Si hago clic en la URL, se descarga automáticamente. Pero cuando trato de publicar algunos datos usando la solicitud POST en la respuesta de axios, obtengo esta forma de manejar. Respuesta de la API

 > PKk)S docProps/PKk)SéÙ£docProps/app.xmlÏ1ƒ0ཿB²kl‡R$êR:w°ÝCrjÀÜIrý÷M)Ô½ããÁÇ{ª]ý”-¢#¬Å±(EhÈ:jñènùEd'5Z=B-6ˆ¢mêh†Àb–Œµ™çJÊhFð:©ÆÔô¼æÃ > ©ï+™—dy*˳„•-Ø|þâ+Vÿ‹Z2Ÿ}ñÙmsòÕë©sšRÉ=(¹ßhÞPKk)S…]ØÓ > docProps/core.xmlm'ËNÃ0E÷|Eä}b;¨²'t*Ø ÎZÄÙ¦iùz'´ > uçñ=>šñ‹n“ ú ¬) ÏIÐH[+Ó”äyµLç$ L > 5X'²¨.PKk)S docProps/PKk)SéÙ£docProps/app.xmlÏ1ƒ0ཿB²kl‡R$êR:w°ÝCrjÀÜIrý÷M)Ô½ããÁÇ{ª]ý”-¢#¬Å±(EhÈ:jñènùEd'5Z=B-6ˆ¢mêh†Àb–Œµ™çJÊhFð:©ÆÔô¼æÃ > ©ï+™—dy*˳„•-Ø|þâ+Vÿ‹Z2Ÿ}ñÙmsòÕë©sšRÉ=(¹ßhÞPKk)S…]ØÓ > docProps/core.xmlm'ËNÃ0E÷|Eä}b;¨²'t*Ø ÎZÄÙ¦iùz'´ > uçñ=>šñ‹n“ ú ¬) ÏIÐH[+Ó”äyµLç$ L 5X'²¨.

llamada a la API

 ```const formData = new FormData(); formData.append("DealerID", DealerID); formData.append("FomDate", fromdate); formData.append("ToDate", toDate); formData.append("FixedDateParameter", FixedDateParameter); formData.append("export_type", export_type); //api const dashboardexport_response = await dashboardexport({ formData });```

tableroexportación

 let url = API + "/dashboard/dashboardexport"; formData.append("pcp_user_id", pcp_user_id); formData.append("role_id", role_id); formData.append("user_id", user_id); try { const response = await axios.post(url, formData, { header }); return response.data; } catch (error) { throw Error(error); } };```
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puedes hacer algo como esto:

 axios.post(url, { method: 'GET', responseType: 'blob', // important }).then((response) => { const url = window.URL.createObjectURL(new Blob([response.data])); const link = document.createElement('a'); link.href = url; link.setAttribute('download', `${Date.now()}.xlsx`); document.body.appendChild(link); link.click(); });

fuente

about 4 years ago · Juan Pablo Isaza Report

0

import axios, { AxiosRequestConfig } from 'axios'; import fs from 'fs'; export const downloadXLSFile = async () => { // Its important to set the 'Content-Type': 'blob' and responseType:'arraybuffer'. const headers = {'Content-Type': 'blob'}; const config: AxiosRequestConfig = {method: 'GET', url: URL, responseType: 'arraybuffer', headers}; try { const response = await axios(config); const outputFilename = `${Date.now()}.xls`; // If you want to download file automatically using link attribute. const url = URL.createObjectURL(new Blob([response.data])); const link = document.createElement('a'); link.href = url; link.setAttribute('download', outputFilename); document.body.appendChild(link); link.click(); // OR you can save/write file locally. fs.writeFileSync(outputFilename, response.data); } catch (error) { throw Error(error); } }
about 4 years ago · Juan Pablo Isaza Report

0

Vale la pena señalar que las otras respuestas se olvidan de eliminar el elemento de enlace de la página después de la descarga.

 const url = window.URL.createObjectURL(new Blob([data.data])); const link = document.createElement('a'); link.href = url; link.setAttribute( 'download', `${Date.now()}.xlsx`, ); document.body.appendChild(link); link.click(); link.remove();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!