在Chrome中获取扩展文件夹内的本地文件 [英] Get local file inside the extension folder in Chrome

查看:3441
本文介绍了在Chrome中获取扩展文件夹内的本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我无法从扩展目录中获取本地文件。是否有可能在扩展目录本身中获取一个文件

解决方案

是的,您可以,但前提是你知道文件路径;因为没有办法获取目录列表。



如果路径已知, chrome.extension.getURL 将会返回扩展范围中的文件URL。
$ b

例如: chrome.extension.getURL('some_folder / some_file.js')输出如下所示:

  chrome-extension://kfcphocilcidmjolfgicbchdfjjkmkmh/some_folder/some_file.js 

chrome-extension 加上扩展名id,是地址扩展的根文件夹。注意,即使路径不正确或文件不存在,该函数也会返回一个URL。



另外,如果您需要更强大的功能,您可以阅读全新的 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屋!

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