download file with React axios

kwemy94 @kwemy94 130 XP a posé dans

Bonjour @all j'ai implementé l'impression de document en pdf via mon API Laravel. Le test avec posmant fonctionne très bien. Mais en consommant l'API avec react, un document téléchargé contient un document illisible n'ayant aucun trait avec le document attendu. comment y remedier?```

const getPDF = async () => {

printToPDF(15).then(res => {
console.log(res.data);
const url = window.URL.createObjectURL(new Blob([res.data]));
console.log(url);
window.open(url, '_blank');
 
}).catch(err => {
console.log(err.response);
toast.danger('Oups! Echec de téléchargent');
})

}

  • export const printToPDF = (sector_id, param=null)=>{
    return axios.post(`${baseUrl}/client-download`, param, header, {responseType: 'blob'})
    }

    const getPDF = async () => {

    printToPDF(15).then(res => {
    console.log(res.data);
    const url = window.URL.createObjectURL(new Blob([res.data]));
    console.log(url);
    window.open(url, '_blank');
     
    }).catch(err => {
    console.log(err.response);
    toast.danger('Oups! Echec de téléchargent');
    })
     
     
    }
     

Veuillez vous connecter ou créer un compte pour participer à cette conversation.