gpt4 book ai didi

Javascript通过对话框获取本地文件路径

转载 作者:行者123 更新时间:2023-11-30 12:08:59 24 4
gpt4 key购买 nike

我正在通过 electron 在 node.js 中编写数据库应用程序。用户需要能够从他们系统的任何位置选择一个 json 文件,我需要获取路径或以其他方式将其复制到程序目录。我尝试了多种不同的方法,但唯一能形成对话框的是 <input type="file"> , 但返回的路径为 fakepath在其中(我相信这是为了浏览器安全,但我不再需要它, Electron 应用程序)。感谢任何帮助

最佳答案

您可以使用 dialog.showOpenDialog应用程序接口(interface)。

dialog.showOpenDialog([browserWindow, ]options[, callback])

  • browserWindow BrowserWindow (optional)
  • options Object
    • title String
    • defaultPath String
    • filters Array
    • properties Array - Contains which features the dialog should use, can contain openFile, openDirectory, multiSelections and createDirectory
  • callback Function (optional)

示例

const dialog = require('electron').dialog;
console.log(dialog.showOpenDialog({ properties: [ 'openFile', 'openDirectory', 'multiSelections' ]}));

关于Javascript通过对话框获取本地文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34377670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com