Skip to content

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

@pranabunni

Description

@pranabunni

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions