Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phonegap "new FileTransfer" "is not defined"

Tags:

cordova

I get the following error:

    ReferenceError: FileTransfer is not defined

when i try to create a new instance:

    var ft = new FileTransfer();

Developing with PhoneGap on Linux (debian) Plugins file & file-transfer added of corse

Source:

    var options = new FileUploadOptions();
    options.chunkedMode = false;
    options.fileKey = "file";
    options.fileName = imageURI.substr(imageURI.lastIndexOf('/')+1);
    options.mimeType = "text/plain";

    var params = new Object();
    params.value1 = "test";
    params.value2 = "filename";
    options.params = params;

    try {
            var ft = new FileTransfer();
    }

    catch (e) {
        alert("ERR = "+e);
    }
    alert("I = "+imageURI);

    ft.upload(imageURI, http://test.com/upload.php"), win, fail, options, true);

URL of server is no valid in this example.

The 1st and 2nd alert are being displayed.

No upload request logged on the server in apache access or error logs

Param imageURI is correct and passed via function param (not part of this source)

PhoneGap Version 3.1.0

like image 551
user2911736 Avatar asked Oct 23 '13 14:10

user2911736


2 Answers

Did you add the 'file' or 'file-transfer' plugin?

The Filetransfer plugin is a separate plugin, and you need to add both of them:

cordova plugin add cordova-plugin-file-transfer

Otherwise, the 'FileTransfer' is indeed not defined.

like image 143
Roei Bahumi Avatar answered Sep 23 '22 16:09

Roei Bahumi


Run the following commands in your phonegap project. And it should resolve the issue on your next build.

Access files on device or network (File API):

$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file.git
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-file-transfer.git

See PhoneGap API Documentation - The Command-line Interface for a list of the plugins.

like image 34
Fostah Avatar answered Sep 22 '22 16:09

Fostah