Firebase functions callable - image as argument

泄露秘密 提交于 2020-01-16 18:58:37

问题


I have a firebase function which given some arguments creates a "post" with a title and the such. Is there a way to send an image as an argument which can then be processed by firebase functions and then upload to firebase storage.

I think it is possible by decoding the file/image object to a base64 string which could be then sent as an argument. How would I convert the file object from html file input to base64? On the other side how would firebase functions know that the string is an actual image? How can I tell the size of the image? Is there a limit to the size of arguments given to a firebase callable function?


回答1:


I would do the following:

  1. Let the user upload the file directly into firebase storage in a folder where only the user has access to.

  2. Let a function trigger on upload that takes this image, checks if the user is authorized to put that in the target folder and put the file in there (or whatever you want the function to do exactly).




回答2:


I ditched this question but came across the problem later in a different project. So to anyone seeing it is possible through base 64 strings. It has the restraints that the image cannot be bigger than 10mb but it is easier than trying to "catch" the file after it being uploaded directly.

Here is the solution



来源:https://stackoverflow.com/questions/53725429/firebase-functions-callable-image-as-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!