概述File Handling API 允许已安装的 PWA 成为系统的文件处理目标。通过 Manifest 的 `file_handlers` 注册可接受的类型与入口,并在页面使用 `launchQueue` 获取传入文件进行处理。Manifest 片段{ "file_handlers": [{ "action": "/open", "accept": [{ "mime_type": "text/plain", "file_extensions": [".txt"] }] }] } 接收文件与路由window.launchQueue.setConsumer(async (params) => { for (const f of params.files) { const file = await f.getFile() const text = await file.text() // 路由到编辑器视图 openEditorWithText(text) } }) 工程建议权限与 UX:清晰提示文件用途与来源;处理用户取消与异常。兼容:在不支持平台回退到手动打开/拖拽;在网页端提供上传入口。安全:校验文件类型与大小;避免执行不可信内容。参考与验证Chrome 平台文档(File Handling):https://developer.chrome.com/docs/web-platform/file-handling/web.dev 指南:https://web.dev/articles/file-handling

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
1.951640s