Save document cordova android android ios ionic angular

892 views Asked by At

I am trying to use the cordova-plugin-file plugin to save documents to a local folder on the device. I am doing the following

      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));
          });
    });

I always get the following error

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

I already tried to add this configuration to config.xml but it didn't work.

        <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>
1

There are 1 answers

1
Daniel Vágner On

Do you have permission in AndroidManifest.xml ?

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

I know that this is the same error on android device if you forgot to implement permission.