问题
I want to use FileTransfer to download a file from web server, code is as following:
function downloadFile(url) {
var fileTransfer = new FileTransfer();
var uri = encodeURI(url);
var filepath="www/download/";
fileTransfer.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);
} else {
loadingStatus.increment();
}
};
fileTransfer.download(
uri,
filePath,
function(entry) {
console.log("download complete: " + entry.fullPath);
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
},
false,
{
headers: {
}
}
);
}
when I run my app in simulator or real devide, all hit error message: Uncaught ReferenceError: FileTransfer is not defined.
I have included cordova.js, what is the reason for this error? thanks.
rgds brent
回答1:
This plugin doesn't work from the browser, it will throw a “new FileTransfer is not defined” error. Use a real device to test.
回答2:
You need to install phonegap plugin:
$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
If you already install, probably you need rebuild phonegap platforms:
$phonegap build android
来源:https://stackoverflow.com/questions/16442698/uncaught-referenceerror-filetransfer-is-not-defined-using-cordova-2-7-0