首页 > 解决方案 > 使用 NeutralinoJS 获取输入文件路径

问题描述

如何使用 NeutralinoJS 获取输入文件路径?

我的代码:

<input type="file" id="inputFile">
const inputFilePath = document.getElementById('inputFile').files[0].path
console.log(inputFilePath)

标签: javascripthtmlneutralinojs

解决方案


我认为浏览器不允许您获取文件路径。

您可以改用文件选择器 API os.showDialogOpen(DialogOpenOptions)https ://neutralino.js.org/docs/api/os#osshowdialogopendialogopenoptions

<button onclick="onFileUpload()">
async onFileUpload () {
  let response = await Neutralino.os.showDialogOpen({
    title: 'Select a file'
  })
  console.log(`You've selected: ${response.selectedEntry}`)
}

推荐阅读