File-upload-Angular2-Nodejs
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
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
How can I solve this issue?