File-upload-Angular2-Nodejs icon indicating copy to clipboard operation
File-upload-Angular2-Nodejs copied to clipboard

'No Access-Control-Allow-Origin header is present on the requested resource' issue when trying to access a file in localhost

Open pranabunni opened this issue 7 years ago • 0 comments

I am trying to implement file download in angular 5.For this I trying to retrieve a file located in my localhost using get request and trying to convert it into blob object.

let headers = new HttpHeaders();
headers = headers.set('Accept', 'application/pdf');

return this.http.get('http://localhost/angular5/lesson2.pdf', {
    headers: headers,
    responseType: 'blob'
}).subscribe((res) => {
    var blob = new Blob([res], { type: 'application/pdf' });
    console.log(blob);
    this.fileName(res);
    saveAs(blob, "testData.pdf");
});

in the above code I trying to access a file located in my localhost in get request,but it shows following error screenshot from 2018-05-02 20-30-34 How can I solve this issue?

pranabunni avatar May 03 '18 10:05 pranabunni