2
votes

I'm successfully using the generate-thumbnail cloud function. My code is correctly saving the resized image as 'thumb_', storing the resized image into the correct storage location, and writing the downloadURL to my realtime database.

The cloud function is saving the downloadURL to ref('images')

return admin.database().ref('images').push({path: fileUrl, thumbnail: thumbFileUrl});

My Questions:

1. How can i change the database reference to be dynamic so it will save the downloadURL to a path in the database based on the album the user selected to upload?

Something like:

return admin.database().ref('\albums\{albumId}').push({path: fileUrl, thumbnail: thumbFileUrl});

2. Can i pass the albumId from my client to my cloud function as a variable?

1

1 Answers

2
votes

I found a workaround to my problem by making my Storage hierarchy match my Database hierarchy.

When a user uploads a picture, the cloud function triggered on the storage event gets the file path (fileDir). I store the fileDir into a string

const dbPath = String(fileDir);

Then I push the downloadURL to dbPath in my database ref (since my storage hierarchy matches my database hierarchy) this works.

return admin.database().ref('/' + dbPath).push({hiRes: fileUrl, photoURL: thumbFileUrl});