filmov
tv
Angular File Download From API | Download File Using Angular

Показать описание
Angular File Download From API | Download File Using Angular
This video has demonstration of downloading file using angular from Rest API. I have shown Download file using angular in a detailed way in this video.
---------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
In the component, we have to add dependency of the created service and subscribe to the download method of the service to download file using angular. In the subscribe method, we have to read the response header to get the file name which is being returned from Rest API. The header will have content-disposition, we need to split it by semi colon(;) and then by equals(=) to get the file name. Then we have to create Blob from the Response Body. Response Body will have file content that we do file download in angular. We have to create a hyperlink. Its href should be URL form of Blob which we can get using window.CreateURLFromObject and the file name should be mentioned in download property of the hyperlink.
--------------------------------------------------------------------------------------------
You may encounter CORS issue if the angular app is running on a different url and the api is running at the different url. CORS should be enabled at the API end. CORS will add the required headers to allow angular download file.
As we are reading the file name from api while downloading the file in angular, at the api end, it should allow reading content-disposition header.
---------------------------------------------------------------------------------------------
#AngularDownloadFileRestAPI# #AngularDownloadFile# #AngularFileDownloadFromAPI#
Chapters
00:00 - Intro
This video has demonstration of downloading file using angular from Rest API. I have shown Download file using angular in a detailed way in this video.
---------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
In the component, we have to add dependency of the created service and subscribe to the download method of the service to download file using angular. In the subscribe method, we have to read the response header to get the file name which is being returned from Rest API. The header will have content-disposition, we need to split it by semi colon(;) and then by equals(=) to get the file name. Then we have to create Blob from the Response Body. Response Body will have file content that we do file download in angular. We have to create a hyperlink. Its href should be URL form of Blob which we can get using window.CreateURLFromObject and the file name should be mentioned in download property of the hyperlink.
--------------------------------------------------------------------------------------------
You may encounter CORS issue if the angular app is running on a different url and the api is running at the different url. CORS should be enabled at the API end. CORS will add the required headers to allow angular download file.
As we are reading the file name from api while downloading the file in angular, at the api end, it should allow reading content-disposition header.
---------------------------------------------------------------------------------------------
#AngularDownloadFileRestAPI# #AngularDownloadFile# #AngularFileDownloadFromAPI#
Chapters
00:00 - Intro
Комментарии