webUtils
一個用於與 Web API 物件(檔案、Blob 等)互動的工具層。
程序:渲染器
方法
webUtils
模組具有以下方法
webUtils.getPathForFile(file)
file
File - 一個網頁 File 物件。
返回 string
- 此 File
物件指向的檔案系統路徑。如果傳入的物件不是 File
物件,則會拋出例外。如果傳入的 File 物件是在 JS 中建構且沒有磁碟上的檔案作為後盾,則會返回空字串。
此方法取代了先前使用 path
屬性擴充 File
物件的做法。以下包含範例。
// Before
const oldPath = document.querySelector('input').files[0].path
// After
const { webUtils } = require('electron')
const newPath = webUtils.getPathForFile(document.querySelector('input').files[0])