Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can `firebase.functions().httpsCallable` submit files to `functions.https.onCall`?

Background:

  1. We want to allow users to upload files onto our website
  2. The files need to be validated and modified before they are written to Cloud Storage
  3. We also need to authenticate the user before we allow them to upload files
  4. And, we need to do some Firestore calls before the files are written to Cloud Storage

Specifications:

  • We're calling Cloud Functions from the front-end using firebase.functions().httpsCallable
  • The backend uses functions.https.onCall

Question:

How can firebase.functions().httpsCallable submit files to functions.https.onCall?

Thank you in advance.

ABC.

like image 550
ABC Avatar asked Jun 28 '26 17:06

ABC


1 Answers

That's not really an intended use case for callable functions. Callables are meant to send a JSON payload to the server, not a file. If you really want to send a (small) file to a function, you'll need to base64 encode it as a string, and put that string in the JSON payload, then decode it in the function.

Instead, consider allowing the client to upload directly to storage, then use a function to validate it with a storage trigger, and delete it if it's not valid.

like image 169
Doug Stevenson Avatar answered Jun 30 '26 15:06

Doug Stevenson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!