FileSystem
约 1 分钟阅读
- wicg.github.io/file-system-access
- w3c.github.io/FileAPI
- web.dev/file-system-access
- web.dev/browser-fs-access
- Chrome
- Chrome 86+
- window.showOpenFilePicker
- navigator.storage.getDirectory
- Chrome 86+
- dataurl 支持 blob:, filesystem:
<a href="" download="filename.txt">- 触发下载- download 依赖服务端返回 Content-Disposition
const dirHandle = await window.showDirectoryPicker();
const saveFileHandle = await self.showSaveFilePicker({
suggestedName: 'Untitled Text.txt',
types: [
{
description: 'Text documents',
accept: {
'text/plain': ['.txt'],
},
},
],
});
const openFileHandle = await self.showOpenFilePicker({
// desktop, documents, downloads, music, pictures, videos
startIn: 'pictures',
// startIn: dirHandle,
});
// 创建目录
const neoDirHandle = await dirHandle.getDirectoryHandle('neo', { create: true });
// 创建文件
const readmeFileHandle = await neoDirHandle.getFileHandle('README.txt', { create: true });
// 删除文件
await neoDirHandle.removeEntry('README.txt');
// 递归删除目录
await dirHandle.removeEntry('neo', { recursive: true });Origin Private File System
- OPFS - Origin Private File System
- chromestatus
- dev 94, trail 95, shiping 99
// FileSystemDirectoryHandle
const root = await navigator.storage.getDirectory();Drop as Handle
elem.addEventListener('dragover', (e) => {
// Prevent navigation.
e.preventDefault();
});
elem.addEventListener('drop', async (e) => {
// Prevent navigation.
e.preventDefault();
// Process all of the items.
for (const item of e.dataTransfer.items) {
// Careful: `kind` will be 'file' for both file
// _and_ directory entries.
if (item.kind === 'file') {
const entry = await item.getAsFileSystemHandle();
if (entry.kind === 'directory') {
handleDirectoryEntry(entry);
} else {
handleFileEntry(entry);
}
}
}
});关联信息
反向链接和本文引用的外部资料。
References
GitHub
2 条- GoogleChromeLabs/text-editor/src/inline-scripts/fs-helpers.jsgithub.com/GoogleChromeLabs/text-editor/blob/main/src/inline-scripts/fs-helpers.js
- WICG/file-system-access/EXPLAINER.mdgithub.com/WICG/file-system-access/blob/main/EXPLAINER.md
其他外链
8 条- developer.mozilla.org/en-US/docs/Web/API/Window/showOpenFilePickerdeveloper.mozilla.org/en-US/docs/Web/API/Window/showOpenFilePicker
- developer.mozilla.org/en-US/docs/Web/HTML/Element/adeveloper.mozilla.org/en-US/docs/Web/HTML/Element/a
- developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Dispositiondeveloper.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
- w3c.github.io/FileAPIw3c.github.io/FileAPI
- web.dev/browser-fs-accessweb.dev/browser-fs-access
- web.dev/file-system-accessweb.dev/file-system-access
- wicg.github.io/file-system-accesswicg.github.io/file-system-access
- www.chromestatus.com/feature/5702777582911488www.chromestatus.com/feature/5702777582911488