Property 'dataDirectory' does not exist on type 'File'

Hi guys !

I’m trying to make a download functionality in my Ionic 3 app, but i’m stucked with the File plugin.

this.fileTransfer.download(url, this.file.dataDirectory + fileName, true).then((entry) => {
            //here logging our success downloaded file path in mobile.
            console.log('download completed: ' + entry.toURL());
        }, (error) => {
            //here logging our error its easier to find out what type of error occured.
            console.log('download failed: ' + error);
        })

I get this error : Property ‘dataDirectory’ does not exist on type ‘File’

Here is my constructor (assume that I’ve imported the File plugin):

constructor(public navCtrl: NavController, public navParams: NavParams, public viewCtrl : ViewController, public rest_api: RestApiProvider,
            private loadingCtrl: LoadingController, private sanitizer: DomSanitizer, private transfer: FileTransfer, private file: File,
            private globalService: GlobalService, public modalCtrl: ModalController) {
  }

Thanks for your help :slight_smile:

Ok guys sorry for this useless post, just saw PHPStorm hasn’t automaticly imported the plugin.
I feel stupid right now :joy:

How you solved this problem please let me know I stuck with this.

1 Like

I hadn’t import the plugin, that’s all ^^
But maybe show some code so we can help

Put the solution in code, please. I’ve been trying for two days and I’m trying to do this.

import {FileTransfer, FileTransferObject} from "@ionic-native/file-transfer";
import { File } from '@ionic-native/file';

export class YourClassName {
    fileTransfer: FileTransferObject;

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

With this your code should work (don’t forget to import your plugins like me).

Also, you should test this functionality of file download on probably a mobile device or an emulator(like provided by Genymotion)

1 Like

Yes, it won’t work without an emulator or a real device :wink:

1 Like