kwemy94
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 () => {
2 
3 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');
8 
9 }).catch(err => {
10 console.log(err.response);
11 toast.danger('Oups! Echec de téléchargent');
12 })
13}
1const getPDF = async () => {
2 
3 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');
8 
9 }).catch(err => {
10 console.log(err.response);
11 toast.danger('Oups! Echec de téléchargent');
12 })
13}
maestrombody
a répondu

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

Confirmer la suppression

Êtes-vous sûr de vouloir supprimer cette réponse ? Cette action est irréversible.

kwemy94
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 ];
8 
9 $pdf = PDF::loadView('download.client_par_secteur', $data)->setPaper('a4', 'landscape')->setWarnings(false);
10 
11 // return $pdf->download('client.pdf');exit
12 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 ];
8 
9 $pdf = PDF::loadView('download.client_par_secteur', $data)->setPaper('a4', 'landscape')->setWarnings(false);
10 
11 // return $pdf->download('client.pdf');exit
12 return $pdf->stream();
13 }
Confirmer la suppression

Êtes-vous sûr de vouloir supprimer cette réponse ? Cette action est irréversible.

Il faut Se connecter ou Créer un compte pour participer à cette conversation.

Confirmer la suppression

Êtes-vous sûr de vouloir supprimer ce sujet ? Cette action est irréversible.