I'm using the cordova's FileTransfer
plugin with the ionic-native
wrapper. The app runs successfully in iPhone simulator but when I run the app in my mobile device I get the error in the console as:
ORIGINAL EXCEPTION: ReferenceError: Can't find variable: FileTransfer
with some stack trace.
Findings:
FileTransfer
in console returns its object. So, it is clear that it has been initializedfile-transfer
plugin creates the problem.Plugins used
cordova-plugin-camera
cordova-plugin-datepicker
cordova-plugin-file-transfer
cordova-plugin-whitelist
Specifications:
Code:
import {Injectable} from '@angular/core';
import {Transfer} from 'ionic-native';
@Injectable()
export class MyClass {
fileTransfer = new Transfer();
constructor(){
}
public upload (url: string, image: string, onProgress: any, opt?: any){
let options = {
fileKey: "file",
mimeType: "image/png",
chunkedMode: false
}
this.fileTransfer.onProgress(onProgress);
return this.fileTransfer.upload(image, this.baseUrl + url, options);
}
}
Uninstalling all the plugins and just running ionic run ios
command fixed this issue. Since the ionic state reset
also does the same thing, this might be a problem with the CLI.