使用 nodejs/electron 获取文件的绝对文件位置

Get the absolute file location of a file using nodejs/electron

如何在不上传文件的情况下使用文件选择器获取文件的绝对位置。我的主要目标是在电子应用程序中流式传输用户选择的媒体文件。

您可以使用内置的dialog.showOpenDialog方法:

// For Electron 12 and later
// Install '@electron/remote' module
// const electronRemote = require('@electron/remote')

// For Electron <12
const electronRemote = require('electron').remote

const currentWindow = electronRemote.getCurrentWindow()
const options = { 
  properties: ['openFile'] 
}
electronRemote.dialog.showOpenDialog(currentWindow, options)
  .then(result => {
    const filePath = result.filePaths[0]
    console.log(filePath)
  })
  .catch(error => {
    console.error(error)
  })