Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpExternal to 'downloads' works in Android but not in iOS #41

Open
afilp opened this issue Jan 29, 2022 · 3 comments
Open

cpExternal to 'downloads' works in Android but not in iOS #41

afilp opened this issue Jan 29, 2022 · 3 comments

Comments

@afilp
Copy link

afilp commented Jan 29, 2022

Hello,

While it works in iOS, the cpExternal does not work in iOS. Note that I have both UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace enabled. Testing in emulator. Shouldn't the destination ('downloads') be a "common" folder and not an application-specific folder?

Is this a bug or a non-proper implementation?

Thanks a lot!

image

const fetchPayment = async (paymentId, createdDate) => {
  const token = await getAuthToken();
  console.log('token', token);

  const destPath = `${Dirs.CacheDir}/${createdDate}-Invoice.pdf`;

  // const date = new Date();
  const { data } = await new Promise((resolve, reject) => {
    try {
      FileSystem.fetch(
        `${window.our.BASE_URL}/payment?paymentId=${paymentId}`,
        {
          headers: {
            Authorization: `Bearer ${token}`,
            Accept: 'application/pdf',
            'Content-Type': 'application/pdf',
          },
          path: destPath,
        },
      )
        .then(async res => {
          console.log('res', res);
          await FileSystem.cpExternal(
            destPath,
            `${createdDate}-Invoice.pdf`,
            'downloads',
          );
          Alert.alert(
            t('invoiceDownloaded'),
            t('invoiceDownloadedAndroidFolder'),
          );
          resolve(res);
        })
        // Something went wrong:
        .catch((errorMessage, statusCode) => {
          console.log(errorMessage);
          reject(errorMessage);
        });
    } catch (err) {
      console.log(err);
      reject(err);
    }
  });
  return data;
};
@alpha0010
Copy link
Owner

File is put where os says it should be. Best as I can tell, that is always sandboxed within the app (might not be true for macos, but I do not use that). Apple procedure for sharing files between apps is by marking the files as sharable (the settings you have enabled). With that, the iOS system file browser should be able to select files from this app for other apps to open.

If you find native api to allow otherwise, let me know.

@afilp
Copy link
Author

afilp commented Feb 1, 2022

Thanks @alpha0010, I am OK to leave the file within the app's sandbox. The problem is that cpExternal throws an error while I am using the expected code. As you see from the message, it just tries to copy from "CacheDir" to "downloads" (which is the app's downloads) and it fails.
Am I doing something wrong in the code? I believe I am using just the standard code.

I do not see any app specific folder in the Files app, could this be the case?

@alpha0010
Copy link
Owner

Oops, sorry, my vision just skipped over the non-English text (or maybe the screenshot did not load for me before?). That is probably a bug.

However, try using cp(), and putting files in Dirs.DocumentDir. I think that should show up in the Files app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants