Ionic v5 React TSX File Transfer Plugin - Can't Understand Example

I’m new to React and TS so maybe I’m just an idiot but so far I’ve been doing fine building out my app but I need to use the file-transfer plugin and this is where everything breaks down.

constructor(private transfer: FileTransfer, private file: File) { } doesn’t work under the imports and only works if I put it in a class, however then “FileTransfer” is viewed as a value and not a type. However if it’s outside of the class then it gets the error cannot find name constructor.

Then fileTransfer.download() gets me Duplicate identifier ‘fileTransfer’.ts(2300)

I could share with you the code that I have but honestly it’s just a patch-work piece of garbage that has nothing working so instead I’ll show you what I wanted to work

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

    const fileTransfer: TransferObject = this.transfer.create();

    function getLatestTealist() {

        const url = 'http://dandtea.com/tealist.json';

        fileTransfer.download(url, this.file.dataDirectory + 'current_compressed.json').then((entry) => {

            console.log('download complete: ' + entry.toURL());

            // MAKE TOAST SAYING "LATEST VERSION GRABBED"

        }, (error) => {

            // handle error

            alert(error);

        });

And maybe someone can help me understand how to make that work. I really appreciate it.

did you see this?

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

    let fileTransfer = FileTransfer.create();
    fileTransfer.download(url, this.file.dataDirectory + 'current_compressed.json').then((entry) => {
        console.log('download complete: ' + entry.toURL());
        // MAKE TOAST SAYING "LATEST VERSION GRABBED"
    }, (error) => {
        // handle error
        alert(error);
    });
1 Like

I see! I didn’t see that, I saw that Using React? but then saw the next that also said “Using React?” with code under it so I followed that guide.

I have exactly what you have but I’m still getting:

Property 'download' does not exist on type 'FileTransferOriginal'.ts(2339)

I appreciate you helping me out here :slight_smile:

EDIT: To be clear I have fun npm install @ionic-native/core
npm install cordova-plugin-file-transfer
npm install @ionic-native/file-transfer
ionic cap sync

EDIT 2: I have tried updating to

import { FileTransfer, FileUploadOptions, FileTransferObject } from ‘@ionic-native/file-transfer/ngx’;

and that also gives

Property 'download' does not exist on type 'typeof FileTransfer'.  TS2339

@teamcoltra sorry, missed a line, see answer edited above… also i have similar examples posted on youtube channel - https://www.youtube.com/channel/UCMCcqbJpyL3LAv3PJeYz2bg

    let fileTransfer = FileTransfer.create();

you don’t need the ngx

1 Like

Hey Aaron,

It took me a while to actually try this out and such but this is, indeed, working perfectly. You are a champion. Thank you so much.

1 Like