ABC
ABC

Reputation: 399

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:

Question:

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

Thank you in advance.

ABC.

Upvotes: 8

Views: 3181

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317788

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.

Upvotes: 6

Related Questions