使用具有Cloud Functions的下载网址从Firebase存储中删除文件 [英] Delete a file from firebase storage using download url with Cloud Functions

查看:64
本文介绍了使用具有Cloud Functions的下载网址从Firebase存储中删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firestore数据库中有一个配置文件集合,并且有一个名为"profilePicture"的字段,其值为downloadUrl.

I have a collection of profiles in my Firestore db and a field named "profilePicture" with a downloadUrl as the value.

我正在使用云功能,并且已经尝试了很长时间以弄清楚如何删除profilePicture.

Im using cloud functions and been trying for a long time to figure out how to delete the profilePicture when the profile is deleted.

我知道删除个人资料时如何创建触发器并获取个人资料图片downloadUrl,但是如何仅使用downloadUrl从存储中删除文件?

I know how to create a trigger when the profile is deleted and get the profile picture downloadUrl, but how do I delete the file from storage with only the downloadUrl?

推荐答案

我的理解是用于云存储的节点SDK 无法将HTTP URL转换为存储桶中的文件路径.相反,您应该将文件路径和下载URL一起存储在文档中.这样便可以构建一个File对象,该对象可用于在需要时删除图像.

My understanding is that the node SDK for Cloud Storage can't convert HTTP URLs into file paths within a storage bucket. Instead, you should be storing the file path along with the download URL in document. This will make it possible for to build a File object that can be used to delete the image when it's time to do so.

这篇关于使用具有Cloud Functions的下载网址从Firebase存储中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆