在Chrome中获取扩展文件夹内的本地文件 [英] Get local file inside the extension folder in Chrome
问题描述
我知道我无法从扩展目录中获取本地文件。是否有可能在扩展目录本身中获取一个文件?
是的,您可以,但前提是你知道文件路径;因为没有办法获取目录列表。
如果路径已知, chrome.extension.getURL
将会返回扩展范围中的文件URL。
$ b
例如: chrome.extension.getURL('some_folder / some_file.js')
输出如下所示:
chrome-extension://kfcphocilcidmjolfgicbchdfjjkmkmh/some_folder/some_file.js
另外,如果您需要更强大的功能,您可以阅读全新的 FileSystem API's 。有了这个,您可以创建,读取,导航和写入用户本地文件系统的沙盒部分。
I know that I can't get a local file from within the extension directory. It is possible to get a file that is inside the extension directory itself?
Yes you can, but only if you know the file path; because there's no way to get the directory listing.
If the path is known, chrome.extension.getURL
will return the file URL in the extension scope.
For example: chrome.extension.getURL('some_folder/some_file.js')
outputs something like this:
chrome-extension://kfcphocilcidmjolfgicbchdfjjlfkmh/some_folder/some_file.js
The chrome-extension
protocol plus the extension id, is the address of extension's root folder. Note this function will return a URL even if the path is incorrect or the file doesn't exist.
Also, if you need something more powerfull, you can read about the brand new FileSystem API's. With this you can create, read, navigate, and write to a sandboxed section of the user's local file system.
这篇关于在Chrome中获取扩展文件夹内的本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!