lundi 27 août 2018

Laravel 5 Angular 5 No 'Access-Control-Allow-Origin' header is present on the requested resource

I want to download a file from my Laravel 5.5 through my Angular 5 project. After clicking on the button it shows me the following error:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.

My Angular code is written below (for download the image, which is stored in a remote server). Note, I manually added the image URL in the variable pathI for your understanding. My intention is to download the image from remote server.

getCarWarehouseImageDownload() { 
        let pathI = "http://localhost/projectName/3/";
        this.http.get(pathI, { responseType: 'blob' }).subscribe(val => {
          let url = URL.createObjectURL(val);
          let a: any = document.createElement('a');
            a.href = url;
            a.download = 'demo.png';
            document.body.appendChild(a);
            a.style = 'display: none';
            a.click();
            a.remove();

          URL.revokeObjectURL(url);
        });
  }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire