webUtils
與 Web API 物件(Files、Blobs 等)互動的實用工具層
程序: 渲染器
方法
webUtils
模組具有以下方法
webUtils.getPathForFile(file)
file
File - 一個 web 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])