How to Use File Saver in Ionic

In this blog, we will discuss how to use file saver in the Ionic app development framework. Before going to discuss that we need to know what is file saver? File saver is the solution for save files on your end especially for the web end. If you want to download images and any doc in ionic then using npm file saver.

Step 1:

First, install the npm package in your project.

npm i file-saver

Step 2:

In your ts file import file saver to the package include in your ts file.

import { saveAs } from 'file-saver';

Step 3:

At last, in your HTML click function include and the function body in your ts file.


{{md.file_name}}
async downloadUrl(urll){ //window.open('https://gexpr.com:8080/users_contents/message/1611323071333.png', '_self'); console.log("file download:"+urll); const url = urll var name=url.substring(url.lastIndexOf('/')+1); saveAs(url, name); }

Conclusion:

This function downloads a file with the file name and it downloads in your browser. This is very important for Ionic app development. Hope you liked the blog. Please share your reviews in the comment section.

Comments

We Serve clients globally in diverse industries

Stay Upto Date With Our Newsletter.