【问题标题】:Simple example with window.requestFileSystem() functionwindow.requestFileSystem() 函数的简单示例
【发布时间】:2012-09-26 18:25:00
【问题描述】:

我有下一个问题:我尝试在 Chrome 中使用 window.requestFileSystem() 函数,但它失败了。找我的步骤:

1)我在 Chrome 中添加了“允许从文件访问文件”标志(见下面的 img):

2)我重新启动了系统。

3)然后我运行带有“允许文件访问文件”标志的 Chrome。

4) 毕竟我尝试启动这个示例代码:

function onInitFs(fs) {
  console.log('Opened file system: ' + fs.name);
}

    function errorHandler(e)
{
    console.log("Error");
}    
    window.requestFileSystem(window.TEMPORARY, 5*1024*1024 /*5MB*/, onInitFs, errorHandler);

但它失败了:

我的行为有什么问题?

【问题讨论】:

    标签: javascript jquery google-chrome google-chrome-devtools


    【解决方案1】:

    此代码在 chrome 中适用于我。我实际上将它用于phonegap,但我首先在笔记本上的chrome上对其进行了测试,浏览器顶部出现了一个黄色栏,要求我允许该网络应用程序永久存储在我的本地驱动器上。

        navigator.webkitPersistentStorage.requestQuota(1024*1024, 
            function(grantedBytes) {
                window.requestFileSystem(window.PERSISTENT, grantedBytes, onInitFs, errorHandler);
            }, 
            function(errorCode) {
                alert("Storage not granted.");
            }
        );
    

    【讨论】:

    • 'window.webkitStorageInfo' 已弃用。请改用“navigator.webkitTemporaryStorage”或“navigator.webkitPersistentStorage”。
    【解决方案2】:

    你应该改变

    window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; 
    

    window.RequestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; 
    

    (R应该大写。)

    【讨论】:

    • 不,R 不应该大写。只有类型是大写的。函数用驼峰式写法。
    【解决方案3】:

    使用以下命令从命令行打开 chrome

    chrome --allow-file-access-from-files
    

    【讨论】:

      【解决方案4】:

      这是因为这个功能目前只有前缀可用,即window.webkitRequestFileSystem

      你可能会觉得这个教程很有趣:http://www.html5rocks.com/en/tutorials/file/filesystem/

      【讨论】:

        猜你喜欢
        • 2014-07-18
        • 2020-04-02
        • 1970-01-01
        • 1970-01-01
        • 2014-09-18
        • 2013-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多