我遇到了Phonegap FileTransfer API的问题。目前我正在尝试运行以下示例代码:
saveFile: function (filepath,location, filetype) {
console.log("FUNCTION BEING CALLED");
var self = this;
//filepath is path to the internets file
//location is where on the device the file will be stored
var fileTransfer = new FileTransfer();
fileTransfer.download(filepath,self.rootPath + location + '.' + filetype,
function (entry) {
console.log('############# DOWNLOAD WORKS ##############');
console.log("download complete: " + entry.fullPath);
},
function (error) {
console.log('############# DOWNLOAD FAILS ##############');
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
}
)
}
目前,似乎没有任何事情发生。没有标记错误,并且回调似乎没有被触发。我得到的只是“功能正在呼唤”的初始console.log。
我已经仔细检查了,并且可以确认我包含了cordova js文件,(cordova-2.4.0.js
)。
如果重要的话,我在Android模拟器,HTC One X和三星Galaxy S3上尝试了这一点,结果都相同。
有谁知道造成这种情况的原因是什么?
编辑:我也觉得我应该提到它也在Angular JS应用程序中运行。
答案 0 :(得分:0)
这就是我在项目中的表现
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
window.fileSystem = fileSystem;
//create directory test_app
fileSystem.root.getDirectory("test_app", {
create : true,
exclusive : false
}, dirWallpaper, fail);
function fail(evt) {
}
function dirWallpaper(entry) {
//save the directory path
window.testDir = entry;
}
//now download file to that location
saveFile: function (filepath,location, filetype) {
console.log("FUNCTION BEING CALLED");
var self = this;
//filepath is path to the internets file
//location is where on the device the file will be stored
var fileTransfer = new FileTransfer();
var path = window.testDir.fullPath + "/test_pdf."+ filetype;
fileTransfer.download(filepath,path,
function (entry) {
console.log('############# DOWNLOAD WORKS ##############');
console.log("download complete: " + entry.fullPath);
},
function (error) {
console.log('############# DOWNLOAD FAILS ##############');
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log("upload error code" + error.code);
}
)
}
尝试这样,让我知道。