0

I'm facing the following issue:

  1. I upload an Image to Firebase Storage
//Start the upload
await StorageHandler.instance.uploadTask(mediaIDPath, largeFile);
  1. Once the upload is completed, the Firebase Extension "Resize Image" will be triggered. The Resized Imaged will be stored separately in another path in my FirebaseStorage

  2. In order to make sure that the image is resized I'm waiting 4 seconds in my code (which is not the right way how to solve this problem)

//Start the upload
await StorageHandler.instance.uploadTask(mediaIDPath, largeFile);

//After the upload is completed, wait 4 seconds until the image is resized
await Future.delayed(Duration(seconds: 4));
  1. Then I'm fetching the URL of the resized Image. I need the download URL immediately in order to display image in a GridView as soon as the image is resized and added to the other path which I've mentioned in point 2.
//Start the upload
await StorageHandler.instance.uploadTask(mediaIDPath, largeFile);

//After the upload is completed, wait 4 seconds until the image is resized
await Future.delayed(Duration(seconds: 4));

//fetch the imageURL of the resized Image
gridURL = await StorageHandler.instance.getImageURLFromStorage(mediaIDPathResizedFile);

To wait 4 seconds is not the right way. Therefore I'm seeking for a possibility to get a feedback from the Storage that the Resize is completed that I can fetch the download URL afterwards. I couldn't find any method in Firebase which provides this functionality.

Important note: I don't want to resize the image on client side to avoid more upload operations and keep the firebase costs at the minimum!

Does anyone have an idea for a workaround to avoid waiting 4 seconds in my case?

I hope I explained my problem clear enough and looking forward for helpful suggestions.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Ayrix
  • 433
  • 5
  • 16

1 Answers1

1

There is nothing built into the resize images extension to signal completion to the calling client.

The typical way to implement this yourself would be to create a Cloud Function that triggers when a file being written to Cloud Storage, and if the file is a thumbnail to implement the send a signal to the calling client (for example, by storing information in the metadata of the file on how to reach the client) through something like FCM, or one of Firebase's databases (Realtime Database, or Cloud Firestore).

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thanks for you answer Frank. I think this would be best approach but I'm not that familiar writing cloud functions since I'm quite a beginner. Could you suggest some best practice websites where I can learn everything that is needed to write Cloud functions? Thanks – Ayrix Apr 24 '22 at 02:56
  • 1
    I included links to the relevant documentation in my answer, which is a great place to start. If you're more into doing than reading, the [codelab for Cloud Functions](https://codelabs.developers.google.com/codelabs/firebase-cloud-functions/) might also be helpful. – Frank van Puffelen Apr 24 '22 at 03:30