我正在编写 Chrome 应用程序,该应用程序可处理本地文件、存储在 indexedbd 中的本地链接。
我的逻辑:
- 在 bd 中保存本地链接;
- 从indexedBD获取本地链接。
- 通过本地链接将文件上传到文件系统。
- 出于任何目的使用文件系统中的文件。
以下代码不起作用:
window.requestFileSystem(TEMPORARY, 1024 * 1204, function(fileSystem) {
fs = fileSystem;
cwd = fs.root;
//renderImages(cwd);
}, onError);
fs.root.getFile('C:\Images\Test\cat.jpg', {create: true, exclusive: true}, function (fileEntry) {
if (fileEntry.isFile === true) {
$("#myimage").attr("src", fileEntry.toURL());
}
});
$("#myimage").attr("src", fileEntry.fullpath);
Error: GET chrome-extension://acnoddeoamaikpmmdkehnkppmcgcpfjl/C:ImagesTestcat.jpg net::ERR_FILE_NOT_FOUND
感谢您的建议!
最佳答案
requestFileSystem
创建一个虚拟的沙盒文件系统供您使用,但您无法通过它访问本地文件。您请求的文件系统在创建时基本上是空的。
Chrome 扩展程序原则上无法访问本地文件,但 native host可以绕过它。
Chrome 应用程序可以使用 fileSystem
API请求访问本地文件系统的部分内容。您可以“保留”条目并将其保存在数据库中以供以后重用。
关于javascript - 如何在我的 Chrome 应用程序中访问本地文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27399159/