是否已经有办法让用户在Chrome上选择一个文件夹

Is there already a way to let the user choose a folder on Chrome?

本文关键字:选择 文件夹 一个 Chrome 用户 是否      更新时间:2023-09-26

我一直在尝试将此Chrome代码与chooseEntry类型用作"openDirectory",但我认为它尚未实现,所以我想知道是否已经有其他方法可以做到这一点。

manifest.json:

"permissions": [
    "notifications",
    {"fileSystem": ["write", "directory"]} 
],

Javascript:

chrome.fileSystem.chooseEntry({type:'openDirectory'},function(userDirEntry){
    /*fill with files*/
});

这就是我得到的:

> Uncaught Error: Invalid value for argument 1. Property 'type': Value must be one of: [openFile, openWritableFile, saveFile].

您用错了它,清单应如下所示:

{"fileSystem": ["write", "directory"]},
"permissions": [
    "notifications",
    {"fileSystem": ["write", "directory"]} 
  ],

您可以删除值"写入",也可以不删除。

JavaScript应该是:

chrome.fileSystem.chooseEntry({ type: 'openDirectory'}, callback);

最后,为了使用openDirectory,您至少需要在计算机中安装Chrome v31。