Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 2 years, 7 months ago. Active 5 days ago. Viewed 19k times. Vadim Kotov 7, 8 8 gold badges 45 45 silver badges 60 60 bronze badges. It seems like the browser intercepts the and then immediately tries to follow the redirect.
Are there better ways to do this? I suppose I could write a HttpInterceptor to catch the and modify the request. Or is it better to not have the API respond with a ? Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. Now, in this step, we will install file saver service to download file immediately. So, go to terminal and then run this below command to install file saver. So, write this below code in your typescript file.
Line 4 to Here in these lines, we are getting file extension. And then getting the exact file type. Line Here in this line, we are calling the download service with two parameters fileName and fileType. Line Here in this line, after getting successful api call, we are calling saveAs function from file saver service which we have install above. You can use any server side technology and integrate this example with it for downloading file from server.
I am going to use here Spring Boot framework as a server side technology. I will provide link as well as button, on which user will click and download the file from server. I will also show how to give end users Save as option while downloading file and how to display file content on the browser.
Go through the following steps for creating Angular project to download file from server using Angular. Go through the link Creating Angular Project to create a new project. Make sure you give the project name as angular-file-download.
For Angular 11 , you will find another option to set whether you want to use stricter type or not. Here I am using stricter type and later I will show you how to use stricter type for response and error.
Remember the file extension ts service.
0コメント