firebase.functions().httpsCallable如何将文件提交到function.https.onCall`? [英] How can `firebase.functions().httpsCallable` submit files to `functions.https.onCall`?
问题描述
背景:
- 我们希望允许用户将文件上传到我们的网站上
- 文件需要先进行验证和修改,然后再写入Cloud Storage
- 在允许用户上传文件之前,我们还需要对用户进行身份验证
- 而且,在将文件写入Cloud Storage之前,我们需要进行一些Firestore调用
规格:
- 我们正在使用
firebase.functions().httpsCallable
从前端调用Cloud Functions
- 后端使用
functions.https.onCall
- We're calling Cloud Functions from the front-end using
firebase.functions().httpsCallable
- The backend uses
functions.https.onCall
问题:
firebase.functions().httpsCallable
如何将文件提交到functions.https.onCall
?
谢谢.
ABC.
推荐答案
这实际上并不是可调用函数的预期用例.可调用对象旨在将JSON有效负载发送到服务器,而不是文件.如果您确实要向函数发送一个(小)文件,则需要将base64编码为一个字符串,然后将该字符串放入JSON有效负载中,然后在函数中对其进行解码.
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.
这篇关于firebase.functions().httpsCallable如何将文件提交到function.https.onCall`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!