XHMM / react-native-cloud-store

A react-native module for icloud drive
https://react-native-cloud-store.vercel.app/docs/install/with-crna
MIT License
68 stars 11 forks source link

downloading a file twice seems to fail #25

Open thoth-seshat opened 10 months ago

thoth-seshat commented 10 months ago

I have a setup like this:

    let file;

      await new Promise<void>((resolve, reject) => {
        CloudStore.download(filePath, {
          onProgress: async (progress) => {
            console.log("progress", progress);
            if (progress.progress === 100) {
              file = await CloudStore.readFile(filePath);
              resolve();
            }
          },
        });
      });

The first time I run this, it seems to work fine however, the second time I run this, it will fail. I'm not sure why.

My file path is created like this:

   function mkICloudFilePath(fileName?: string) {
    if (!defaultIPath) return new Error("No default iCloud folder found");

    const iCloudUrl = CloudStore.getICloudURL().then((url) => {
      console.log("iCloudUrl", url);
    });

    console.log("defaultIPath", defaultIPath);

    return CloudStore.PathUtils.join(defaultIPath, `Documents/${fileName}`);
  }

It seems like the file is downloaded but won't persist in the iCloud folder for some reason and then the second time I try to access it it says it doesn't exit. With a WARN Possible Unhandled Promise Rejection (id: 1):

I'm also seeing the progress indicator from the onICloudDocumentsUpdateGathering events showing progress 0 before it dies.

If the file is already downloaded does it die again? I'm confused on what download does vs startDownloadingUbiquitousItem and I'm not sure which should be used. I need to ensure the file exists so I can read it in and process it.

XHMM commented 10 months ago

Re-call download should be fine. Can you log the rejection to see what the error message was?