FileSystemFileHandle: getFile() 方法
注意:此功能在 Web Workers 中可用。
getFile() 方法是 FileSystemFileHandle 介面的一部分,它返回一個 Promise,該 Promise 會解析為一個 File 物件,該物件代表了由該控制代碼表示的磁碟上的狀態。
如果在此方法呼叫後,磁碟上的檔案發生更改或被刪除,則返回的 File 物件可能將不再可讀。
語法
js
getFile()
引數
無。
返回值
異常
NotAllowedErrorDOMException-
如果
read模式下的PermissionStatus.state不是granted,則會丟擲此異常。 NotFoundErrorDOMException-
如果當前條目未找到,則丟擲此異常。
示例
以下非同步函式顯示一個檔案選擇器,一旦選擇了一個檔案,就會使用 getFile() 方法檢索內容。
js
async function getTheFile() {
// open file picker
const [fileHandle] = await window.showOpenFilePicker(pickerOpts);
// get file contents
const fileData = await fileHandle.getFile();
}
規範
| 規範 |
|---|
| 檔案系統 # api-filesystemfilehandle-getfile |
瀏覽器相容性
載入中…