kwemy94
kwemy94 280 XP
asked

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?

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');
})
}
maestrombody
posted

Bonjour. Essaye de faire voir ta fonction au niveau de la l'API

kwemy94
kwemy94 280 XP
posted

voici le contenu de ma fonction au niveau de l'API (c'est juste des données de test)

public function clientDownload($sector_id=15){
$clients = $this->clientRepository->getClientSector($sector_id);
$data = [
'title' => '2S Kollect App',
'date' => date('m/d/Y'),
'clients' => $clients,
];
 
$pdf = PDF::loadView('download.client_par_secteur', $data)->setPaper('a4', 'landscape')->setWarnings(false);
 
// return $pdf->download('client.pdf');exit
return $pdf->stream();
}

You need Log in or Create an account to join the conversation.