Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

There are different approaches to handle multiple users updating the same file in Firebase storage without overwriting the changes made by other users. Here are some possibilities:

  1. Use Firebase Realtime Database to track changes to the file: When a user starts editing a file, you can create a node in the Realtime Database with the file details and the user's ID. When the user saves their changes, you can update the node with the new file content and timestamp. Other users accessing the same file can listen for changes in the Realtime Database and update their local copy accordingly.

  2. Use Firebase Cloud Functions to handle file updates: You can create a Cloud Function that triggers when a file is uploaded or updated in Firebase storage. The function can create a new version of the file with a unique timestamp or version number, and store it in a separate folder. When a user opens the file, they can be directed to the latest version of the file. When a user saves their changes, their changes can be stored in a new version of the file. This ensures that older versions of the file are not overwritten.

  3. Use Firebase Firestore to store file details and versions: You can create a Firestore collection to store file details and versions. When a user starts editing a file, you can create a new document with the file's ID, name, user ID, timestamp, and initial content. When a user saves their changes, a new version of the document can be created with the updated content and timestamp. You can then retrieve the latest version of the file and display it to other users.

  4. Use a locking mechanism: You can implement a locking mechanism that prevents multiple users from editing the same file at the same time. When a user opens a file, you can create a lock document with the file ID and user ID. Other users trying to access the same file can check for the lock document and wait for it to be released. When a user saves their changes, they can release the lock and update the file with their changes.

Overall, the approach you choose will depend on your specific requirements and implementation details.