如何获取Chrome扩展程序的根文件夹?
我是第一次开发 Chrome 扩展,并且正在遵循解释相关内容的唯一指南: HTML5 ROCKS - 文件系统。 我需要为我的扩展获取存储空间,我解决了这样的问题:
window.webkitStorageInfo.requestQuota(window.PERSISTENT,1024*1024, onInitFs, errorHandler);
好的,它可以工作。 现在我需要在根目录中创建一个xml文件,但在“onInitFs”中,“fs”var只是一个数字,“fs.root”无法获取它。
function onInitFs(fs){
console.log(fs.root); // -> Undefined
fs.root.getFile('list.xml', {create: true, exclusive: true}, function(fileEntry) {
fileEntry.isFile === true;
fileEntry.name == 'list.xml';
fileEntry.fullPath == '/list.xml';
}, errorHandler);
}
谁能解释为什么它不起作用以及如何解决这个问题?
I am developing a Chrome Extesion for the first time and I am following the only guide that explains something about that: HTML5 ROCKS - FILESYSTEM.
I need to get storage for my extension and I resolved so:
window.webkitStorageInfo.requestQuota(window.PERSISTENT,1024*1024, onInitFs, errorHandler);
Ok, it works.
Now I need to create a xml file into the root, but in "onInitFs" the "fs" var is only a number and "fs.root" can't get it.
function onInitFs(fs){
console.log(fs.root); // -> Undefined
fs.root.getFile('list.xml', {create: true, exclusive: true}, function(fileEntry) {
fileEntry.isFile === true;
fileEntry.name == 'list.xml';
fileEntry.fullPath == '/list.xml';
}, errorHandler);
}
Can anybody explain why it doesn't work and how to resolve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Chrome 扩展程序中使用 RequestFileSystem
为了将 FileSystem API 用作 Chrome 扩展程序的根文件系统,您实际上可以使用
window.webkitRequestFileSystem
而不是requestQuota
。对于我来说,这确实可以在 Chrome 15,16 和 17 上正确打印:
Using requestQuota for HTML5 apps
仅供参考,这将是实际请求配额的方式(即,当不使用 Chrome 扩展时)。您必须首先请求配额(用户会在他/她的窗口顶部看到一个小横幅)。如果用户接受,则调用 RequestFileSystem。
最终可能需要在扩展中请求配额。目前,可以通过
unlimitedStorage
权限来规避此问题。有关实现/存储类型的当前状态,请参阅 http://code.google.com/ chrome/whitepapers/storage.htmlUsing RequestFileSystem within Chrome Extension
In order to use the FileSystem API as a root filesystem for your Chrome extension, you can actually use
window.webkitRequestFileSystem
instead ofrequestQuota
.This does print correctly on Chrome 15,16 and 17 for me:
Using requestQuota for HTML5 apps
Just for reference, this would be the way to actually request the quota (i.e., when not using a Chrome Extension). You have to request the quota (the user sees a little banner at the top of his/her window) first. The RequestFileSystem is called if the user accepts.
Eventually it might be necessary to request quota within an extension. Currently this can be circumvented with the
unlimitedStorage
permission. For the current state of implementation/storage types, see http://code.google.com/chrome/whitepapers/storage.html在当前稳定版本 17.x 之前,您无法在 Chrome 扩展中使用 HTML5 FileSystem API。我已经尝试过了,如果我在后台页面调用 FileSystem API,浏览器就会崩溃。
以下是您可以在 Chrome 扩展程序中使用的 HTML5 API 列表:
http://code.google.com/chrome/extensions/api_other.html
Until current stable version 17.x, you cannot use HTML5 FileSystem API in Chrome extension. I have try this, the browser will crash down if I call FileSystem API in background page.
And here is a HTML5 API list what you can use in Chrome extension:
http://code.google.com/chrome/extensions/api_other.html