Search code examples
cordovaphonegap-pluginsionic-frameworkphonegap-buildionic-view

File(Transfer) with PhoneGap Build is not working


Since I could not find the answer anywhere else in related questions, I'm posting a new question.

The problem is: when I run my Ionic app via IonicView (useful app to test your application on your device) everything works fine, but when I run my Ionic app after building with PhoneGap Build two specific plugins 'File' and 'FileTransfer' don't work.

I use other plugins like: Camera, Network-information & Geolocation and those work just fine after building with PhoneGap Build and running in IonicView. I'm thinking it has something to do with my config file, but I don't know what it is.

So I have this function:

function uploadPicture(fileURL) {
        var win = function(result) {
            alert('Done!');
        }

        var fail = function(err) {
            alert("Fail!");
        }
        var options = new FileUploadOptions();
        options.fileKey = "file";
        options.fileName = fileURL.substr(fileURL.lastIndexOf('/') + 1);
        options.mimeType = "image/jpeg";
        options.chunkedMode = true;
        options.params = {};
        var ft = new FileTransfer();
        ft.upload(fileURL, encodeURI("http://test.com/upload"), win, fail, options);
    }

The URL is not a valid one for this example. This code won't execute after the line var options = new FileUploadOptions(); because it says that FileUploadOptions() is not defined. Also FileTransfer is not defined. (After building with PhoneGap Build)

This is my config file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="xxx.ionicframework.xxxx"
    version="0.0.1"
    xmlns="http://www.w3.org/ns/widgets"
    xmlns:cdv="http://cordova.apache.org/ns/1.0"
    xmlns:gap="http://phonegap.com/ns/1.0">
<name>XXX</name>
<description>
    XXX
</description>
<author email="xx@xxx" href="http://example.com/">
    XXX
</author>
<content src="index.html"/>
<access origin="*"/>
<preference name="phonegap-version" value="3.7.0" />
<preference name="webviewbounce" value="true"/>
<preference name="UIWebViewBounce" value="true"/>
<preference name="DisallowOverscroll" value="true"/>
<preference name="BackupWebStorage" value="none"/>
<preference name="Orientation" value="landscape" />
<preference name="Fullscreen" value="true" />
<feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
</feature>
<feature name="NetworkStatus">
    <param name="ios-package" value="CDVConnection" />
</feature>
<feature name="File">
    <param name="ios-package" value="CDVFile" />
    <param name="android-package" value="org.apache.cordova.FileUtils" />
</feature>
<feature name="FileTransfer">
    <param name="ios-package" value="CDVFileTransfer" />
    <param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>

<gap:plugin name="com.phonegap.plugin.statusbar" version="1.1.0" />
<gap:plugin name="org.apache.cordova.camera" version="0.3.2" />
<gap:plugin name="org.apache.cordova.device" version="0.2.12" />
<gap:plugin name="org.apache.cordova.file" version="1.3.1" />
<gap:plugin name="org.apache.cordova.file-transfer" version="0.4.6" />
<gap:plugin name="org.apache.cordova.geolocation" version="0.3.10" />
<gap:plugin name="org.apache.cordova.network-information" version="0.2.12" />

</widget>

Anyone who can help me out with any suggestions?


Solution

  • Just read a little comment that you've to install the application again completely (if you have Hydration enabled) when you add a new plugin.

    Now everything is working fine. Fixed!