Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download file from server into Ionic2 App

I am in need to implement a feature in my Ionic2 app where users can download a specific Video file into Ionic2 app.

Upon checking the Ionic Native section, I found that the following plugins available :

  • File
  • File Chooser
  • File Opener
  • File Path

But could not find anything such as 'cordova-plugin-file-transfer' where a specific method exists as DOWNLOAD.

What could be the way out ?

Please suggest.

like image 776
Arup Bhattacharya Avatar asked Jan 04 '23 05:01

Arup Bhattacharya


2 Answers

You should use "Transfer" plugin for downloading a file in ionic2

You can install plugin by this command

ionic plugin add cordova-plugin-file-transfer
npm install --save @ionic-native/transfer

and then import it

import { Transfer, FileUploadOptions, TransferObject } from '@ionic-native/transfer';

set constructor

constructor(private transfer: Transfer, private file: File) { }

Then use this function to download file using url

download() {
const url = 'http://www.example.com/file.pdf';
fileTransfer.download(url, this.file.dataDirectory + 
'file.pdf').then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
// handle error
});
}

Hope it help you You can also upload a file using this Plugin

like image 90
Vishnu Kumar Soni Avatar answered Jan 06 '23 19:01

Vishnu Kumar Soni


You can use Transfer native plugin for that.

This plugin allows you to upload and download files.

Git Repo.

 ionic plugin add cordova-plugin-file-transfer
 npm install --save @ionic-native/transfer
like image 30
Sampath Avatar answered Jan 06 '23 19:01

Sampath