1
votes

[SUMMARY]

For a newly uploaded file to Firebase Cloud Storage I want to determine who uploaded the file (the User's ID token) from within a triggered Firebase Function.

[DETAILS]

I'm allowing the Firebase authenticated mobile user to upload a file to Cloud storage. I've attached a Firebase Cloud Storage trigger via Firebase Function with onFinalize. When a new file is added to Cloud Storage it triggers the function.

From within the function is it possible to determine the mobile user's ID token so that i may use Firebase Cloud Messaging to send a message back? Or do i have to upload the file as before then after upload is complete make a reference to the uploaded file then apply metadata to it (eg. add the User's ID Token which belongs to the mobile user)? I would then have to have a Firebase Function trigger on metadata changes -- when a change occurs i can then read out the ID token for whom the newly uploaded file belongs to.

Mobile: Java Android

Firebase Cloud Functions: Node.js

1

1 Answers

0
votes

The most reliable way to do this is:

  1. Associate the device token with the user's UID before the upload. There might be multiple active device tokens per user depending on how many devices the user is using. This is normal.
  2. When the file is uplaoded, also attach metadata to the file with the user's UID. You can ensure this is correct using security rules.
  3. In the triggered function, match the secured UID with the previously saved tokens, and send each token the message about the upload.