如何从使用 firestore 图像调整大小扩展调整大小的图像中下载 url?

How can I get the dowload url from images that are resized with firestorage image-resize extension?

//making a ref beforehand
const ref = db.collection("impressions").doc().id;

//upload the original file
const bucket = await firebase.storage().ref("impressions/" + ref).put(image);

//this works but I do not need it
const downloadUrl = await firebase.storage().ref("impressions/" + ref).getDownloadURL();

//trying to retrieve the downloadUrl from the files that are most likely still in the process of being created by the image resize extention?
//the ref's are correct

const downloadUrl_image = await firebase.storage().ref("impressions/" + ref + "_1000x1000").getDownloadURL();

const downloadUrl_thumb = await firebase.storage().ref("impressions/" + ref + "_50x50").getDownloadURL();

如何从已调整大小的图片中下载 url?有我可以听的事件吗?还是我需要自己做函数?

感谢您的帮助,

马蒂亚斯

Firebase 扩展非常棒,因为它们允许您快速部署标准业务逻辑,但它们可能在配置选项方面受到限制。

特别是,您将无法直接下载 url 调整大小后的图像。

我可以想到两种可能的方法:

1。在创建调整大小的图像时触发 Cloud Function

在扩展程序配置期间,您定义存储调整大小的图像的路径。

帮助说:

For example, if you specify a path of thumbs and you upload an image to /images/original.jpg, then the resized image is stored at /images/thumbs/original_200x200.jpg.

因此,您预先知道路径的结构和调整大小的图像的名称。因此,您可以在创建这些文件时触发云功能,请参阅 doc。例如,您可以将图像的下载 url 存储在 Firestore 文档中,其 ID 与调整后的图像文件名(或原始文件名)

相同

2。编写您自己的图像调整云功能

官方 Cloud Function 示例集合中有一个示例与扩展完全相同。你会发现它 here on Github. You can also look at the code of the Extension itself.

这样您就可以完全控制 Cloud Functions 逻辑。