是否可以将 FileEntry
转换为标准的 JavaScript 对象 File
?
我在文档中找不到任何有意义的内容 https://developer.chrome.com/apps/fileSystem
最佳答案
FileEntry
documentation确实在此处提供指导:
The
FileSystemFileEntry
interface of the File System API represents a file in a file system. It offers properties describing the file's attributes, as well as thefile()
method, which creates a File object that can be used to read the file.
不幸的是,file()
方法依赖于回调而不是 Promises,但我们可以包装它并使使用 API(和阅读代码)更容易:
async function getFile(fileEntry) {
try {
return new Promise((resolve, reject) => fileEntry.file(resolve, reject));
} catch (err) {
console.log(err);
}
}
// From inside an async method or JS module
let file = await getFile(fileEntry); // Wait until we have the file
关于javascript - 如何使用 chrome 应用程序文件系统将 FileEntry 转换为标准的 JavaScript 文件对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45052875/