Ionic2 FileTransfer Downloding is not working


#1

i have implement Downloading function in my app but i get error…
every time my code is …

import { Component } from ‘@angular/core’;
import { NavController, AlertController,ToastController,Platform } from ‘ionic-angular’;
import { FileTransfer,FileTransferObject } from ‘@ionic-native/file-transfer’;
import { File } from ‘@ionic-native/file’;
@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {

constructor(public navCtrl: NavController,private transfer: FileTransfer, private file: File,public alertCtrl: AlertController,public toastCtrl: ToastController,public platform: Platform) {

}

download() {
const fileTransfer: FileTransferObject = this.transfer.create();
const url = ‘http://rapid-fire-lots.000webhostapp.com/Data/test.pdf’;
fileTransfer.download(url, this.file.dataDirectory + ‘test.pdf’).then((entry) => {
console.log(url);
console.log('download complete: ’ + entry.toURL());
}, (error) => {
console.log(JSON.stringify(error));
});
}
}

home.html -file
<button ion-button block round color=“secondary” (click)=“download()”>Download

error…
Native: tried accessing the FileTransfer plugin but Cordova is not available. Make sure to include cordova.js or run in a device/simulator
cordovaWarn @ util.js:63
checkAvailability @ plugin.js:23
FileTransferObject @ index.js:142
FileTransfer.create @ index.js:118
webpackJsonp.193.HomePage.download @ home.ts:16
(anonymous) @ HomePage.html:15
handleEvent @ core.js:13547
callWithDebugContext @ core.js:15056
debugHandleEvent @ core.js:14643
dispatchEvent @ core.js:9962
(anonymous) @ core.js:10587
(anonymous) @ platform-browser.js:2628
t.invokeTask @ polyfills.js:3
onInvokeTask @ core.js:4740
t.invokeTask @ polyfills.js:3
r.runTask @ polyfills.js:3
e.invokeTask @ polyfills.js:3
p @ polyfills.js:2
v @ polyfills.js:2
util.js:60 Native: tried calling File.dataDirectory, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator


#2

Are you try to run this on browser?
You have to check it on simulation or real device when you are using cordova plugins