I currently spend one day in this issue,still failed to download a file from an url in angular 5
Downloading and hosting AngularJS files locally. This option is for those who want to work with AngularJS offline, or those who want to host the AngularJS files on their own servers. The quickest way to get started is to point your html. The idea was to send a list of file ids through a $http AngularJS call, download the files into a temp folder onto the web server, and trigger the download on the.
when I run above code it shows following error
how can I solve this issue.Can any one post the correct code to download a pdf file from an url in angular 5?
2 Answers
Angular 2 Download File From Url
I think you should define header and responseType like this:
Try this
References:
- Discussion on Angular Github
Not the answer you're looking for? Browse other questions tagged angular5 or ask your own question.
**I'm submitting a bug report
Angular 4 Download File
I believe that I have encountered a bug in angular2 with downloading a file from a Web API.
I know you want a plunkr that demonstrates the problem, but I'm not sure how to do that since we need a web api, as well as the angular2 code.
Current behavior
I am trying to download a file that I created with ClosedXML. I have verified that the file is not corrupt but, for some reason, it works just with Angular1, not Angular2.
Minimal reproduction of the problem with instructions
The web api code to return the file is:
In Angular2, in my web service:
and in my component:
A file IS downloaded, but it is corrupt when I try to access it and is TWICE the size of the file when downloaded with Angular1.
Expected behavior
If I call the SAME API with Angular1, the file is downloaded fine. My service code:
where handleSuccess returns response.data (which I can't get at for angular2)
and the code to invoke the service:
Interestingly enough, in Angular2, if I simply change my webservice to a GET (I wanted POST however, but just to try it out) then got rid of the service code and simply made this call, the file is fine:
window.open(
${AppSettings.REPORTS_API_URL}/Report/MonthlySpreadsheet, '_blank');
So, really, what is the difference here? Why does the same or very similar code work for Angular1 but not Angular2??
Please tell us about your environment:
Windows 10, Web Storem and Visual Studio, Nuget and NPM
Angular version: 2.0.X
2.2.1Browser:
all
I'm sorry to not produce a plunkr here. Hopefully, you can help determine if this is a bug or not. I seriously think it is.
Thank you,
Karen Healey