Javascript window.requestFileSystem() 函数的简单示例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12748920/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple example with window.requestFileSystem() function
提问by abilash
I have next problem: I try to use window.requestFileSystem()
function in Chrome, but it failed. Look for my steps:
我有下一个问题:我尝试window.requestFileSystem()
在 Chrome 中使用函数,但失败了。寻找我的步骤:
1)I added 'allow file access from file' flag to Chrome(see img bellow):
1)我向 Chrome 添加了“允许从文件访问文件”标志(参见下面的 img):
2)I restarted the system.
2)我重新启动了系统。
3)Then I ran the Chrome with 'allow file access file' flag.
3)然后我用“允许文件访问文件”标志运行Chrome。
4) After all I try to launch this sample code:
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);
but It failed:
但它失败了:
What's wrong in my actions?
我的行为有什么问题?
回答by ndm
That's because this functionality is currently only availble prefixed, ie window.webkitRequestFileSystem
那是因为此功能目前仅可用前缀,即 window.webkitRequestFileSystem
You may find this turorial interesting: http://www.html5rocks.com/en/tutorials/file/filesystem/
您可能会发现这个 turorial 很有趣:http://www.html5rocks.com/en/tutorials/file/filesystem/
回答by COBRA.cH
This code works for me in chrome. I actually used it for phonegap, but I tested it first on chrome on my notebook and a yellow bar appeared on the top of the browser, asking me to allow the web app permanent storage on my local drive.
这段代码在 chrome 中对我有用。我实际上将它用于 phonegap,但我首先在笔记本上的 chrome 上对其进行了测试,并且浏览器顶部出现了一个黄色条,要求我允许将 Web 应用程序永久存储在我的本地驱动器上。
navigator.webkitPersistentStorage.requestQuota(1024*1024,
function(grantedBytes) {
window.requestFileSystem(window.PERSISTENT, grantedBytes, onInitFs, errorHandler);
},
function(errorCode) {
alert("Storage not granted.");
}
);
回答by puneet
open chrome from command line using below command
使用以下命令从命令行打开 chrome
chrome --allow-file-access-from-files
回答by user3062037
You should change
你应该改变
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
to
到
window.RequestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
(The R should have been capitalized.)
(R 应该大写。)