Hey guys,
I am using custom build ngCordova for use with files.
Everytime the script reaches the statement in ng-cordova.js:
var fileTransfer = new FileTransfer();
It throws the following error:
ReferenceError: FileTransfer is not defined
at Object.downloadFile (file:///android_asset/www/js/ng-cordova.js:195:32)
at Scope.$scope.download (file:///android_asset/www/js/controllers.js:122:30)
at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:18471:21
at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:43026:9
at Scope.$eval (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:20326:28)
at Scope.$apply (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:20424:23)
at HTMLButtonElement.<anonymous> (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:43025:13)
at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:10478:10
at forEach (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:7950:18)
at HTMLButtonElement.eventHandler (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:10477:5) (17:36:57:458 | error)
I have both FileTransfer and file plugin installed.
I’m calling the download function as such:
$cordovaFile.downloadFile(source, filePath, true)
.then(function (result) {
console.log("Hurray "+result)
}, function (err) {
console.log("Oh bummer");
}, function (progress) {
// constant progress updates
});
Any ideas what might be causing the angular not to find the FileTransfer plugin?
+1 I’m having the very same issue. Have you found a solution yet?
Is this error happening on app loading, or after clicking on a button or some other interaction ?
I created a new project, reinstalled the plugins, rebuilt the app and it’s working now. Thanks anyway!
[EDIT]
Forgot to say I also had to install the File Transfer plugin (https://github.com/apache/cordova-plugin-file-transfer ), which is not explicitly mentioned on the ngCordova documentation page.
1 Like
Im calling the ng-cordova plugin on button click. i’ll try your solution and let you know . SInce i am using Netbeans ide i dont include the cordova.js file and i add the cordova plugins throught the interface. Not sure if that could be a reason.
psyche
October 20, 2014, 2:06pm
6
Maybe You are missing the phonegap plugin? Please take a look at this similar Stack Overflow question:
Stack overflow link
This is included in my config.xml:
<feature name="File">
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
<param name="onload" value="true" />
</feature>
<feature name="FileTransfer">
<param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>
And this is my build output:
add to body class: platform-android
Running command: /home/joseph/NetBeansProjects/Musica/platforms/android/cordova/build
Buildfile: /home/joseph/NetBeansProjects/Musica/platforms/android/build.xml
-set-mode-check:
-set-debug-files:
-check-env:
[checkenv] Android SDK Tools Revision 23.0.2
[checkenv] Installed at /home/joseph/android-sdk-linux
-setup:
[echo] Project Name: Musica
[gettype] Project Type: Application
-set-debug-mode:
-debug-obfuscation-check:
-pre-build:
-build-setup:
[getbuildtools] Using latest Build Tools: 20.0.0
[echo] Resolving Build Target for Musica...
[gettarget] Project Target: Android 4.4.2
[gettarget] API level: 19
[echo] ----------
[echo] Creating output directories if needed...
[echo] ----------
[echo] Resolving Dependencies for Musica...
[dependency] Library dependencies:
[dependency]
[dependency] ------------------
[dependency] Ordered libraries:
[dependency]
[dependency] ------------------
[echo] ----------
[echo] Building Libraries with 'debug'...
nodeps:
-set-mode-check:
-set-debug-files:
-check-env:
[checkenv] Android SDK Tools Revision 23.0.2
[checkenv] Installed at /home/joseph/android-sdk-linux
-setup:
[echo] Project Name: CordovaLib
[gettype] Project Type: Android Library
-set-debug-mode:
-debug-obfuscation-check:
-pre-build:
-build-setup:
[getbuildtools] Using latest Build Tools: 20.0.0
[echo] Resolving Build Target for CordovaLib...
[gettarget] Project Target: Android 4.4.2
[gettarget] API level: 19
[echo] ----------
[echo] Creating output directories if needed...
[echo] ----------
[echo] Resolving Dependencies for CordovaLib...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency]
[dependency] ------------------
-code-gen:
[mergemanifest] Found Deleted Target File
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
[aidl] No AIDL files to compile.
[echo] ----------
[echo] Handling RenderScript files...
[echo] ----------
[echo] Handling Resources...
[aapt] Found modified input file
[aapt] Generating resource IDs...
[echo] ----------
[echo] Handling BuildConfig class...
[buildconfig] No need to generate new BuildConfig.
-pre-compile:
-compile:
[echo] Creating library output jar file...
-post-compile:
-obfuscate:
-dex:
[echo] Library project: do not convert bytecode...
-crunch:
[crunch] Crunching PNG Files in source dir: /home/joseph/NetBeansProjects/Musica/platforms/android/CordovaLib/res
[crunch] To destination dir: /home/joseph/NetBeansProjects/Musica/platforms/android/CordovaLib/ant-build/res
[crunch] Crunched 0 PNG files to update cache
-package-resources:
[echo] Library project: do not package resources...
-package:
[echo] Library project: do not package apk...
-post-package:
-do-debug:
[echo] Library project: do not create apk...
[propertyfile] Updating property file: /home/joseph/NetBeansProjects/Musica/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /home/joseph/NetBeansProjects/Musica/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /home/joseph/NetBeansProjects/Musica/platforms/android/CordovaLib/ant-build/build.prop
[propertyfile] Updating property file: /home/joseph/NetBeansProjects/Musica/platforms/android/CordovaLib/ant-build/build.prop
-post-build:
debug:
-code-gen:
[mergemanifest] Found Deleted Target File
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
[aidl] No AIDL files to compile.
[echo] ----------
[echo] Handling RenderScript files...
[echo] ----------
[echo] Handling Resources...
[aapt] Found modified input file
[aapt] Generating resource IDs...
[echo] ----------
[echo] Handling BuildConfig class...
[buildconfig] No need to generate new BuildConfig.
-pre-compile:
[echo] Set jars path to: /home/joseph/NetBeansProjects/Musica/platforms/android/CordovaLib/ant-build/classes.jar
-compile:
[javac] Compiling 2 source files to /home/joseph/NetBeansProjects/Musica/platforms/android/ant-build/classes
[javac] warning: [options] source value 1.5 is obsolete and will be removed in a future release
[javac] warning: [options] target value 1.5 is obsolete and will be removed in a future release
[javac] warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
[javac] 3 warnings
-post-compile:
-obfuscate:
-dex:
[dex] input: /home/joseph/NetBeansProjects/Musica/platforms/android/ant-build/classes
[dex] input: /home/joseph/NetBeansProjects/Musica/platforms/android/CordovaLib/ant-build/classes.jar
[dex] Using Pre-Dexed classes-8b974013969b3b6fa310d91bd63cca2b.jar <- /home/joseph/NetBeansProjects/Musica/platforms/android/CordovaLib/ant-build/classes.jar
[dex] Found modified input file
[dex] Converting compiled files and external libraries into /home/joseph/NetBeansProjects/Musica/platforms/android/ant-build/classes.dex...
[dx] Merged dex A (64 defs/84.6KiB) with dex B (207 defs/313.7KiB). Result is 271 defs/484.7KiB. Took 0.1s
-crunch:
[crunch] Crunching PNG Files in source dir: /home/joseph/NetBeansProjects/Musica/platforms/android/res
[crunch] To destination dir: /home/joseph/NetBeansProjects/Musica/platforms/android/ant-build/res
[crunch] Crunched 0 PNG files to update cache
-package-resources:
[aapt] Found modified input file
[aapt] Creating full resource package...
[aapt] (skipping file '.bower.json' due to ANDROID_AAPT_IGNORE pattern '.*')
[aapt] (skipping file '.bower.json' due to ANDROID_AAPT_IGNORE pattern '.*')
[aapt] (skipping file '.bower.json' due to ANDROID_AAPT_IGNORE pattern '.*')
[aapt] (skipping file '.bower.json' due to ANDROID_AAPT_IGNORE pattern '.*')
[aapt] (skipping file '.bower.json' due to ANDROID_AAPT_IGNORE pattern '.*')
[aapt] (skipping file '.bower.json' due to ANDROID_AAPT_IGNORE pattern '.*')
[aapt] (skipping file '.bower.json' due to ANDROID_AAPT_IGNORE pattern '.*')
[aapt] (skipping file '.gitignore' due to ANDROID_AAPT_IGNORE pattern '.*')
-package:
[apkbuilder] Found modified input file
[apkbuilder] Creating Musica-debug-unaligned.apk and signing it with a debug key...
-post-package:
-do-debug:
[zipalign] Running zip align on final apk...
[echo] Debug Package: /home/joseph/NetBeansProjects/Musica/platforms/android/ant-build/Musica-debug.apk
[propertyfile] Updating property file: /home/joseph/NetBeansProjects/Musica/platforms/android/ant-build/build.prop
[propertyfile] Updating property file: /home/joseph/NetBeansProjects/Musica/platforms/android/ant-build/build.prop
[propertyfile] Updating property file: /home/joseph/NetBeansProjects/Musica/platforms/android/ant-build/build.prop
[propertyfile] Updating property file: /home/joseph/NetBeansProjects/Musica/platforms/android/ant-build/build.prop
-post-build:
[move] Moving 1 file to /home/joseph/NetBeansProjects/Musica/platforms/android/ant-build
[move] Moving 1 file to /home/joseph/NetBeansProjects/Musica/platforms/android/CordovaLib/ant-build
debug:
BUILD SUCCESSFUL
I have the same problem and it is driving me crazy…
Try going to plugins then delete android.json and ios.json which ever exists then build again and try.
Let me know if that works for you.
I finally found the problem… I had to execute the code after device is ready. Newbie problems haha.
Thank you!!
Hey DerrickRoccka,
How exactly did you sort this? I have the same issue and can’t seem to fix it even during the device ready stage.
Thanks
First backup your www directory in another directory outside the project. Then delete then entire thing.
After that do the following commands:
ionic start [Your Project Name] blank
cd [Your Porject Name]
npm install cordova
ionic platform add android
ionic pludin add [file plugin url]
ionic plugin add [file transfer plugin url ]
Then check in your plugins directory that all the plugin folders exist.
After that check your android.json or ios.json and make sure it references all
First backup your www directory in another directory outside the project. Then delete then entire thing.
After that do the following commands:
ionic start [Your Project Name] blank
cd [Your Porject Name]
npm install cordova
ionic platform add android
ionic pludin add [file plugin url]
ionic plugin add [file transfer plugin url ]
ionic build android
Then check in your plugins directory that all the plugin folders exist.
After that check your android.json or ios.json and make sure it references all the plugins installed.
Then check platform/android/asset/www/cordova_plugin.js and make sure all the plugin information is in there as well.
Also test your app on a mobile device or an emulator and not in the browser.
Sorry for a need of a second post but my hand slipped
hi tutchmedia! I’m sorry to reply so late. I did not realize. I just tried, nothing else. Could we have different issues then?
Have you solved it?
Cheers!
For those using ngCordova, you can file the file transfer plugin url here:
http://ngcordova.com/docs/plugins/fileTransfer/
Hope this helps those still encounter issue uploading
I found a solution.
As others have mentioned, and after making sure the File and FileTransfer plugins were properly installed, I removed my android platform, re-added it, built it, and then tested on the device with success.
.
These were my steps (From the command line):
ionic platform remove android
(made sure the “adroid” folder in the “platforms” folder was now gone)
ionic platform add android
ionic build android
ionic run
(assuming you have a device plugged in to your pc so “ionic run” will load the app on your device)
Hope this can help someone.
sajith
April 6, 2017, 6:14am
17
after button click it will happen what can i do