FileSystemFileHandle.getFile()
Baseline 2023Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
FileSystemFileHandle
インターフェイスの getFile()
メソッドは、ハンドルが表すエントリーのディスク上の状態を表す File
オブジェクトで解決する Promise
を返します。
このメソッドが呼び出されたあと、ディスク上のファイルが変更されたり削除されたりすると、返された File
オブジェクトはおそらく読み込めなくなるでしょう。
構文
js
getFile()
引数
なし
返値
例
- NotAllowedError
-
読み込みモードの
PermissionStatus.state
がgranted
でないとき投げられます。
例
以下の非同期関数は、ファイルピッカーを開き、ファイルが選択されると getFile()
メソッドを用いて中身を取得します。
js
async function getTheFile() {
// ファイルピッカーを開く
[fileHandle] = await window.showOpenFilePicker(pickerOpts);
// ファイルの中身を取得する
const fileData = await fileHandle.getFile();
}
仕様書
Specification |
---|
File System # api-filesystemfilehandle-getfile |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
getFile |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.