在Chrome应用程序中无限制的文件存储 [英] unlimited file storage in chrome app

查看:729
本文介绍了在Chrome应用程序中无限制的文件存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将无限数量的文件保存到用户硬盘驱动器,而不会让用户单击对话框。

我在使用无限存储时看到的唯一文档是: https://developers.google.com/chrome/whitepapers/storage ,它表示它只适用于Chrome应用。



我所见过的所有关于Chrome fileSystem API的示例都表明,为了创建一个新文件并写入它,用户需要从 chrome.fileSystem.chooseEntry 函数,这意味着用户需要通过一个对话框。
$ b 常规 fileSystem API看起来好像可以将文件保存到用户的扩展沙箱中,而不会让用户通过一个对话框,但我想知道,它是否具有仅适用于应用程序的unlimitedStorage权限?如果只有Chrome API拥有该权限,那么这并不会让我感到震惊。



如果我使用常规的 fileSystem API,我需要使用窗口请求文件系统.webkitRequestFileSystem (我有点惊讶 window.requestFileSystem 在Chrome中不适用于我),但该方法需要 type persistenttemporary), size (应用程序需要存储的字节)参数。

你显然不会在Chrome API中这样做。但是,正常的 fileSystem API可以让您在使用配额管理API时请求更多的存储空间,这也记录在上面链接的页面上。



并在 https://developers.google。 com / chrome / apps / docs / developers_guide#manifest ,它表示:


权限字段可让您指定应用程序需要的HTML5权限。通过指定unlimitedStoragenotifications,这个应用程序可以使用这些HTML5功能,而无需重复询问用户许可。在应用程序安装过程中,用户被告知应用程序需要哪些权限;安装应用程序隐式授予那些URL匹配清单中apps字段中所有网页的权限。


所以我希望unlimitedStorage权限仅仅意味着我可以调用 window.webkitRequestFileSystem (window.PERSISTENT,anySize,successCallback),而不是要求用户在需要时提高配额,Chrome会自动执行此操作。



问题1:有谁知道这是否正常?然而,如果只有chrome API具有unlimitedStorage权限,那么我可以尝试创建一个文件条目使用常规API,并将该条目传递给Chrome API函数,从而跳过对对话框的需求,并获得对unlimitedStorage权限的访问权限。



问题2:是否可以在一个API中创建条目并将其传递给另一个?恐怕不同的API可能有不同的沙箱。
$ b $ < fileSystem API的文档并不好,所以我想我会问是否有人从以往的经验中知道。首先,为了避免混淆,这里被称为打包的应用程序应该被称为Chrome应用程序。



如果blob被任何其他应用程序使用,则必须获取 FileEntry 通过 chrome.fileSystem.chooseEntry ,这样数据就会被写入到用户可以访问的计算机文件系统中。 (你可以从用户那里获得一个目录,并保存保留的条目,并使用它,而不要求用户每次都做出选择。)

如果blob仅适用于该Chrome应用程序,您可以使用文件API而不调用 chrome.fileSystem.chooseEntry



至于限制,你是正确的, unlimitedStorage 允许无限存储。在我的实验中,尽管有文档,但我从来没有能够让Chrome应用程序要求用户授权特定数量。我使用该许可,似乎没有限制。我读到的Google文档看起来不准确。



如果您正在写入外部文件系统,则在调用 chrome.fileSystem.chooseEntry ,没有限制,您不需要 unlimitedStorage 权限。


I want to save an unlimited number of files to the users hard drive, without making the user click through a dialog box.

The only documentation I have seen on using unlimited storage is here: https://developers.google.com/chrome/whitepapers/storage, which says that it is only available to Chrome apps.

All of the examples I have seen of the Chrome fileSystem API suggest that in order to create a new file and write to it, the user needs to obtain an entry object from the chrome.fileSystem.chooseEntry function, which means the user needs to go through a dialog box.

The regular fileSystem API looks like it can save a file to the user's extension sandbox without making the user go through a dialog box, but I'm wondering, does it have the "unlimitedStorage" permission that is only given to apps? It wouldn't shock me if only the Chrome API has that permission.

If I use the regular fileSystem API, I need to request the filesystem using window.webkitRequestFileSystem (I'm a little surprised window.requestFileSystem isn't working for me in Chrome), but the method takes type ("persistent" or "temporary"), and size (the bytes the app will require for storage) arguments.

You obviously don't do that in the Chrome API. However, the normal fileSystem API lets you request more storage when you need it using the Quota Management API, which is also documented on the page I linked above

And on https://developers.google.com/chrome/apps/docs/developers_guide#manifest, it says:

The "permissions" field lets you specify HTML5 permissions that the app requires. By specifying "unlimitedStorage" and "notifications", this app is able to use those HTML5 features without having to repeatedly ask the user for permission. During app installation, the user is told which permissions the app needs; installing the app implicitly grants those permissions for all pages whose URLs match those in the "apps" field of the manifest.

So I'm hoping that the "unlimitedStorage" permission simply means that I can just call window.webkitRequestFileSystem(window.PERSISTENT, anySize, successCallback), and instead of asking the user to raise the quota when it needs to, Chrome automatically does it.

Question 1: Does anyone know if that's the way it works?

However, if only the the chrome API has that "unlimitedStorage" permission, I could try creating a file entry with the regular API, and passing that entry into the Chrome API functions, therefore skipping the need for a dialog box, and gaining access to the "unlimitedStorage" permission.

Question 2: Is it possible for me to create the entry in one API and pass it to the other? I'm afraid the different API's might have different sandboxes.

The documentation on the fileSystem API's isn't great, so I figured I'd ask to see if anybody knew from previous experience. The fewer rabbit holes the better.

解决方案

First of all, to avoid confusion, what here is being called a "packaged app" should be called a "Chrome App".

If the blob is to be used by any other app, you must obtain a FileEntry via chrome.fileSystem.chooseEntry so the data will be written to the computer's file system where the user can access it. (You can obtain a directory that way from the user and save the retained entry, and use that without asking the user to make a choice every time.)

If the blob is only for use by that Chrome App, you can use the file API without calling chrome.fileSystem.chooseEntry.

As for limits, you're correct that unlimitedStorage allows unlimited storage. In my experiments, despite the documentation, I have never been able to get a Chrome App to ask the user to authorize a specific amount. I use that permission, and there seems to be no limit. The Google documentation I've read on this appears to be inaccurate.

If you're writing to the external file system, after you've called chrome.fileSystem.chooseEntry, there are no limits and you don't need unlimitedStorage permission.

这篇关于在Chrome应用程序中无限制的文件存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆