Show sync status & add ability to trigger sync of (*.icloud) files
Closed this issue · 3 comments
Is your feature request related to a problem (i.e. user experience)?
When writing a file "A.xyz" on device 1, on device 2 I can see a file "A.xyz.icloud". This file is only visible if I log the contents of the directory. I have (to my knowledge) no means to trigger the synchronization of this specific file
Describe the feature you'd like to suggest
Add a function that triggers the sync of the specific file
Additional context
Add any other context or screenshots about the feature request here.
What exactly is your use-case? I'm asking because, AFAIK, there's no option to trigger an iCloud sync manually from the uploader's perspective. The OS decides when to perform a sync. There is, however, a function on the receiver side to start downloading a given file in the ubiquity container: startDownloadingUbiquitousItemAtURL
.
The mentioned function is not currently implemented in react-native-cloud-storage, though. I don't see a good reason to implement it, to be honest: The OS should already automatically download the file when you call readFIle()
on the receiver side. You should not have to trigger a sync / download beforehand. If it's not synced already, the OS will download it and then return the contents. I could be wrong about this though as I haven't tested this for some time.
So, this depends on your use-case:
- If you run your app on two devices and want to sync data back and forth, calling
readFile()
should be enough to sync a download before the OS tries to actually read the file (no guarantee – let me know if this is not the case). - If you upload a file from e.g. an iPhone and want to read it in another app, e.g. Finder on a Mac, the app on the receiver side, in this case, Finder, is responsible for downloading the file. You can't do it from your app on the iPhone.
Hi Max,
Thanks for the fast response. The sync "up" triggers immediately - the problem is with the download - same app, different device.
Given the two functions below, when you createRandomFile (randomfile.txt) on device 1, device 2 will have a ".randomfile.txt.icloud" (note . in the beginning and .icloud in the end).
Calling readRandomFile on device 1 logs "random input data", but on device 2 it generates an error (File or directory randomfile.txt not found)
const createRandomFile = async () => {
await CloudStorage.writeFile("/" + "randomfile.txt", "random input data");
};
const readRandomFile = async () => {
const files = await CloudStorage.readdir("/");
console.log("files:", files);
const content = await CloudStorage.readFile("/" + "randomfile.txt");
console.log("content:", content);
};
Downloading non-synced files from iCloud is now possible in 1.2.1 using downloadFile()
.
To check if a file needs to be downloaded, simply read the directory contents using readdir()
and see if the file ends with an .icloud
extension.