Back

document_already_exists error when uploading to storage with ID.unique()

  • 0
  • Flutter
  • Cloud
d_honig
20 May, 2024, 14:01

Occasionally (twice in the last two days) I get an error document_already_exists when uploading an image to storage. I am using ID.unique. The code to upload the image:

TypeScript
final storage = Storage(client);
final file = await storage.createFile(
    bucketId: storageId,
    fileId: ID.unique(),
    file: InputFile.fromPath(
        path: event.imagePath!,
        filename: event.imagePath!.split("/").last));

This doesn't happen every time, but it has happened twice in the last two days. What could be causing this and how to fix it?

TL;DR
Issue: Error "document_already_exists" occurs sporadically when uploading images to storage using ID.unique. Solution: The error is likely due to a coincidence where the generated unique ID matches an existing document ID in the storage. To resolve this, consider implementing a check for the existence of a document with the generated ID before uploading to ensure uniqueness.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more