Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call refFromURL in Firebase Cloud Function

I'm storing references to files in Firebase Cloud Storage using URLs. In firebase client code, you can call firebase.storage().refFromURL(photo.image) to get the actual storage reference and do handy things like call delete with it. How do I accomplish the same thing in a cloud function (specifically a realtime database trigger)? I want to be able to clean up images after deleting the object that references them.

like image 575
Greg Gilley Avatar asked Jul 11 '17 21:07

Greg Gilley


People also ask

What is the difference between onCall http callable and onRequest HTTP request Functions?

onRequest creates a standard API endpoint, and you'll use whatever methods your client-side code normally uses to make. HTTP requests to interact with them. onCall creates a callable. Once you get used to them, onCall is less effort to write, but you don't have all the flexibility you might be used to.


1 Answers

Here is a one-liner.

const refFromURL = (URL) => decodeURIComponent(URL.split('/').pop().split('?')[0])
like image 161
Manan Sharma Avatar answered Oct 17 '22 21:10

Manan Sharma