【问题标题】:Phonegap - Check if File existsPhonegap - 检查文件是否存在
【发布时间】:2013-06-11 13:19:52
【问题描述】:

我现在的问题是,我无法检查Documents Folder (iOS) 中是否已存在文件。 我用 ajax 试了一下,效果很好,但是我不能在我的代码中使用 jQuery 语法。

我希望有这样的解决方案:

if(fileExists('path/to/file.txt'))
{
    alert('make me happy');
}
else
{
    alert('why u make me sad?');
}

我也试过了

window.resolveLocalFileSystemURI(fileSource, success, fail);

但我需要返回,我不能使用新功能。

而使用FileReader 是废话:/

希望你能帮我找到解决办法。

【问题讨论】:

  • 使用 FileReader 有什么问题?
  • 我要检查多个大小未知的文件,我想性能会很差

标签: jquery ios jquery-mobile cordova


【解决方案1】:
String.prototype.fileExists = function() {
    filename = this.trim();

    var response = jQuery.ajax({
        url: filename,
        type: 'HEAD',
        async: false
    }).status;  

    return (response != "200") ? false : true;
}

【讨论】:

  • 到目前为止它对我来说是这样的:if(fileSource.fileExists()) 我会尝试更多并给你反馈:)
  • 对我来说仍然有一些问题,如果文件超过 100Mb,我的应用程序在 iPad 上崩溃。 ://
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多