【问题标题】:Save document cordova android android ios ionic angular保存文档cordova android android ios ionic angular
【发布时间】:2022-01-24 00:52:10
【问题描述】:

我正在尝试使用cordova-plugin-file 插件将文档保存到设备上的本地文件夹中。 我正在做以下事情

      await this.file.checkDir(folderPath, directory).then(async res => {
        console.log("checkDir", res);
          await this.file.writeFile(folderPath + directory, fileName, document, options).then(res => {
            console.log("fileName", fileName);
            console.log("document", document);
              response = {
                  ...response,
                  success: true,
                  error: res,
                  data: res
              };
              resolve(response);
              })
              .catch(error => reject(error));
          }).catch(async () => {
              await this.file.createDir(folderPath, directory, true).then(async directory => {
                  await this.file.writeFile(folderPath + directory.name, fileName, document, options).then(res => {
                    console.log("fileName", fileName);
                    console.log("document", document);
                      response = {
                          ...response,
                          success: true,
                          error: res,
                          data: res
                      };
                      resolve(response);
                  }).catch(error => reject(error));
              })
              .catch(error => reject(error));
          });
    });

我总是收到以下错误

FileError: {"code":9,"message":"INVALID_MODIFICATION_ERR"}

我已经尝试将此配置添加到 config.xml,但没有成功。

        <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
        <application android:requestLegacyExternalStorage="true" android:usesCleartextTraffic="true" />
    </edit-config>

【问题讨论】:

    标签: angular cordova ionic-framework cordova-plugin-file


    【解决方案1】:

    你有 AndroidManifest.xml 的权限吗?

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    

    我知道如果您忘记实现权限,Android 设备上也会出现同样的错误。

    【讨论】:

    • 我正在尝试将其保存在 this.file.dataDirectory + '/Download/' 中,这样可以吗?
    猜你喜欢
    • 1970-01-01
    • 2021-07-02
    • 2018-08-11
    • 1970-01-01
    • 2021-03-16
    • 2018-03-19
    • 2018-12-14
    • 2021-11-01
    • 1970-01-01
    相关资源
    最近更新 更多