简体   繁体   English

Firebase 扩展“Resize Images”完成后是否有办法获得反馈? - Flutter Firebase 存储

[英]Is there a way to get a feedback from the Firebase extension "Resize Images" once it is completed? - Flutter Firebase Storage

I'm facing the following issue:我面临以下问题:

  1. I upload an Image to Firebase Storage我将图像上传到 Firebase 存储
//Start the upload
await StorageHandler.instance.uploadTask(mediaIDPath, largeFile);
  1. Once the upload is completed, the Firebase Extension "Resize Image" will be triggered.上传完成后,将触发 Firebase 扩展“Resize Image”。 The Resized Imaged will be stored separately in another path in my FirebaseStorage调整大小的图像将单独存储在我的 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)为了确保调整图像大小,我在代码中等待 4 秒(这不是解决此问题的正确方法)

//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.然后我正在获取调整大小后的图像的 URL。 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.我需要立即下载 URL,以便在调整图像大小并添加到我在第 2 点中提到的其他路径后立即在 GridView 中显示图像。
//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.等待 4 秒不是正确的方法。 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.因此,我正在寻求从存储中获得调整大小已完成的反馈的可能性,以便我可以在之后获取下载 URL。 I couldn't find any method in Firebase which provides this functionality.我在 Firebase 中找不到任何提供此功能的方法。

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!重要说明:我不想在客户端调整图像大小以避免更多上传操作并将 firebase 成本保持在最低水平!

Does anyone have an idea for a workaround to avoid waiting 4 seconds in my case?有没有人有解决方法的想法,以避免在我的情况下等待 4 秒?

I hope I explained my problem clear enough and looking forward for helpful suggestions.我希望我足够清楚地解释我的问题,并期待有用的建议。

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).自己实现这一点的典型方法是创建一个Cloud Function当文件写入 Cloud Storage 时触发,如果文件是缩略图,则向调用客户端发送信号(例如,通过将信息存储在关于如何到达客户端的文件的元数据)通过 FCM 或 Firebase 的数据库之一(实时数据库或 Cloud Firestore)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM