réponses
213 vues
kwemy94
330 XP
a posé
download file with React axios
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?
1const getPDF = async () => {23 printToPDF(15).then(res => {4 console.log(res.data);5 const url = window.URL.createObjectURL(new Blob([res.data]));6 console.log(url);7 window.open(url, '_blank');89 }).catch(err => {10 console.log(err.response);11 toast.danger('Oups! Echec de téléchargent');12 })13}1const getPDF = async () => {23 printToPDF(15).then(res => {4 console.log(res.data);5 const url = window.URL.createObjectURL(new Blob([res.data]));6 console.log(url);7 window.open(url, '_blank');89 }).catch(err => {10 console.log(err.response);11 toast.danger('Oups! Echec de téléchargent');12 })13}
kwemy94
330 XP
a répondu
voici le contenu de ma fonction au niveau de l'API (c'est juste des données de test)
1public function clientDownload($sector_id=15){2 $clients = $this->clientRepository->getClientSector($sector_id);3 $data = [4 'title' => '2S Kollect App',5 'date' => date('m/d/Y'),6 'clients' => $clients,7 ];89 $pdf = PDF::loadView('download.client_par_secteur', $data)->setPaper('a4', 'landscape')->setWarnings(false);1011 // return $pdf->download('client.pdf');exit12 return $pdf->stream();13 }1public function clientDownload($sector_id=15){2 $clients = $this->clientRepository->getClientSector($sector_id);3 $data = [4 'title' => '2S Kollect App',5 'date' => date('m/d/Y'),6 'clients' => $clients,7 ];89 $pdf = PDF::loadView('download.client_par_secteur', $data)->setPaper('a4', 'landscape')->setWarnings(false);1011 // return $pdf->download('client.pdf');exit12 return $pdf->stream();13 }
Il faut Se connecter ou Créer un compte pour participer à cette conversation.