I'm trying to use the FileTransfer Ionic 4 example.
I've performed the installation steps:
ionic cordova plugin add cordova-plugin-file
npm install @ionic-native/file
I've created a service:
import { Injectable } from '@angular/core';
import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer/ngx';
import { File } from '@ionic-native/file';
@Injectable({
providedIn: 'root'
})
export class DownloadService {
fileTransfer: FileTransferObject;
constructor(private transfer: FileTransfer, private file: File) {
this.fileTransfer = this.transfer.create();
}
download(url: string, destFileName: string) {
this.fileTransfer.download(url, this.file.dataDirectory + destFileName).then((entry) => {
console.log('download complete: ' + entry.toURL());
}, (error) => {
console.log('download failed' + error);
});
}
}
However, this results in compilation error:
ERROR in src/app/services/download.service.ts(20,47): error TS2339: Property 'dataDirectory' does not exist on type 'File'.
I've seen a similar question. However, I'm importing correctly as suggested by the accepted answer, so I believe this question is different.
Try this :
import { File } from '@ionic-native/file/ngx';
When using Ionic4, you have to add /ngx
to every @ionic-native
imports. Basically, it provides an Ionic4 dedicated typing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With