Android 未捕获引用错误:未定义文件传输(使用cordova 2.7.0)
我想使用FileTransfer从web服务器下载文件,代码如下:Android 未捕获引用错误:未定义文件传输(使用cordova 2.7.0),android,cordova,Android,Cordova,我想使用FileTransfer从web服务器下载文件,代码如下: function downloadFile(url) { var fileTransfer = new FileTransfer(); var uri = encodeURI(url); var filepath="www/download/"; fileTransfer.onprogress = function(progressEvent) { if (progr
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: {
}
}
);
}
当我在模拟器或real Device中运行我的应用程序时,所有命中错误消息:未捕获引用错误:未定义文件传输
我已经包括cordova.js,这个错误的原因是什么?谢谢
rgds
brent您需要安装phonegap插件:
$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
如果已经安装,可能需要重建phonegap平台:
$phonegap build android
此插件无法在浏览器中运行,它将抛出“未定义新文件传输”错误。使用真实设备进行测试。开始时设置
文件路径
,但稍后在.download()中使用文件路径
。这只是一个复制/粘贴错误吗?是的,复制/粘贴错误应该是“filepath”。错误发生在“var fileTransfer=new fileTransfer();”行。有解决方法吗?