Ionic 通过离子服务器在Web浏览器上运行时,从离子电容器文件系统writeFile保存的文件位置

fcipmucu  于 2022-12-08  发布在  Ionic
关注(0)|答案(1)|浏览(155)

我正在使用https://capacitorjs.com/docs/apis/filesystem
取自该站点的示例代码为:

import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';

const writeSecretFile = async () => {
  await Filesystem.writeFile({
    path: 'secrets/text.txt',
    data: "This is a test",
    directory: Directory.Documents,
    encoding: Encoding.UTF8,
  });
};

当我通过Web /ionic serve运行程序时
在哪里可以找到保存的文件:secrets/text.txt在我的计算机上?

pftdvrlh

pftdvrlh1#

The plugin's source code (Capacitor v4.0.1) reveals the web plugin tries to use IndexedDB, and fails if IndexedDB is not available.
Check out the initDb() method:

if (!('indexedDB' in window)) {
    throw this.unavailable("This browser doesn't support IndexedDB");
}

Using the example from the documentation, you can check the result in the Developper tools:

Capacitor uses static names ("DOCUMENTS", "CACHE", "DATA", etc) as the counterpart to native paths for the web.
Note that the fact that it is not explained in the documentation might indicate that the implementation could change at any time.

相关问题