Cordova   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Cordova 3.4.0上的FileSystem失败“无法创建目标文件”大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我最近将我的iOS Cordova项目从2.7.0升级到3.4.0. 升级后文件系统访问被破坏. (然似乎在模拟器中工作?) 我收到一条错误消息,指出“无法创建目标文件”,我google了一下,并虑将我的“完整路径”更改为“toURL()”,但无济于事.我真的不知道下一步该尝试什么? 这是我的下载代码 window.requestFileSystem( LocalFileSystem.PERS
@H_696_7@
我最近将我的iOS Cordova项目从2.7.0升级到3.4.0.

升级文件系统访问被破坏. (然似乎在模拟器中工作?)

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

这是我的下载代码

window.requestFileSystem(
LocalFileSystem.PERSISTENT,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代码和提供的示例之间的差异.

结果我没有在我的下载源url(doh)上做encodeURI()

所以完整的,有效的代码

window.requestFileSystem(
LocalFileSystem.PERSISTENT,function onFileSystemsuccess(fileSystem) {
fileSystem.root.getFile(
"dummy.html",{
create: true,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,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);
@H_801_48@

大佬总结

以上是大佬教程为你收集整理的Cordova 3.4.0上的FileSystem失败“无法创建目标文件”全部内容,希望文章能够帮你解决Cordova 3.4.0上的FileSystem失败“无法创建目标文件”所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。