cordova - Cordova 3.4.0 上的文件系统失败 "Could not create target file"

标签 cordova phonegap-plugins cordova-plugins

我最近将我的 iOS Cordova 项目从 2.7.0 升级到 3.4.0。

升级后文件系统访问被破坏。 (不过似乎可以在模拟器中工作?)

我收到一条错误消息,指出“无法创建目标文件”,我用谷歌搜索并想将我的“完整路径”更改为“toURL()”,但无济于事。我真的不知道下一步该尝试什么?

这是我的下载代码

window.requestFileSystem(
LocalFileSystem.PERSISTENT, 0,

function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
    "dummy.html", {
    create: true,
    exclusive: false
},

function gotFileEntry(fileEntry) {
    var sPath = fileEntry.toURL().replace("dummy.html", "");
    var fileTransfer = new FileTransfer();
    fileEntry.remove();

    fileTransfer.download(
        "https://dl.dropbox.com/u/13253550/db02.xml",
    sPath + "database.xml",

    function (theFile) {
        console.log("download complete: " + theFile.toURI());
        showLink(theFile.toURI());
        setTimeout(function () {
            checkConnection();
        }, 50);
    },

    function (error) {
        console.log("download error source " + error.source);
        console.log("download error target " + error.target);
        console.log("upload error code: " + error.code);
    });
},
fail);
},
fail);

最佳答案

我找到了文件插件 ( link ) 和 fileTransfer 插件 ( link ) 的文档

在原始问题中进行更改后,我想知道文件插件部分是否正常,并开始寻找我的 fileTransfer 代码与提供的示例之间的差异。

结果我没有在我的下载源网址上执行encodeURI() (doh)

完整的工作代码:

window.requestFileSystem(
LocalFileSystem.PERSISTENT, 0,

function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(
"dummy.html", {
create: true,
exclusive: false
},

function gotFileEntry(fileEntry) {
var sPath = fileEntry.toURL().replace("dummy.html", "");
var fileTransfer = new FileTransfer();
fileEntry.remove();
var DBuri = encodeURI("https://dl.dropbox.com/u/13253550/db02.xml");
fileTransfer.download(
    DBuri,
sPath + "database.xml",

function (theFile) {
    console.log("download complete: " + theFile.toURI());
    showLink(theFile.toURI());
    setTimeout(function () {
        checkConnection();
    }, 50);
},

function (error) {
    console.log("download error source " + error.source);
    console.log("download error target " + error.target);
    console.log("upload error code: " + error.code);
});
},
fail);
},
fail);

关于cordova - Cordova 3.4.0 上的文件系统失败 "Could not create target file",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22213355/

相关文章:

java - 防止后退按钮退出 Cordova 插件内的 Android 应用程序

使用 cordova 插件的 angularjs cordova 应用程序

android - 导航后,iframe中的YouTube视频继续播放-Android和Phonegap

javascript - Facebook cordova 登录错误 : 'Failed to instantiate module facebookApp due to..'

android - 以编程方式更改 Android 键盘布局类型?

ios - 将目标设置为 '_blank' 时,iOS 上的 Cordova InAppBrowser 插件问题,页面不断加载

javascript - PhoneGap - 打开外部应用程序

javascript - Cordova - iOS 嵌套元素禁用反弹但保持速度滚动

javascript - 在制作Phonegap应用程序时,我应该如何添加列表项并将其保存到本地存储?

ios - 如何通过 config.xml 将 NSPhotoLibraryUsageDescription 添加到 plist 文件?