I’ve been reading a lot of questions of how to use the Upload Files flow function, and how to make this work with Firebase Storage. So I decided to look into this myself, and after some trial and error, I managed to get this to work with a successful file upload to my Firebase Storage bucket.
This example does not use Authentication. I just set my Storage rules to allow all reads/writes to keep this simple:
Here is how I did it:
First, Create a List of Objects variable. I called mine PAGE_FileListObj:
This example is simple. It just lets the user pick a file from the Pick Files flow function, and uploads this file to Firebase.
Going through each flow function, from start to end:
-
I am just Initializing the FileListObj variable by setting it to empty. This is more tricky than it should be because to do this I have to add an empty value, then remove that value, so it initializes to 0 items. This is necessary i discovered because the WITH_ITEM function we will use below wont work unless the variable is initialized first.
-
Pick Files. Configure this however you want, I set mine to display Images only and Multiple Files = false. So it just allows 1 file to be chosen.
-
Set the FileListObj variable:
Since I am only selecting 1 file from Pick Files, the file index i want is always going to be [0]. So I use a WITH_ITEM function to append {outputs[“Pick files”].files[0]} to my initialized FileListObj variable. But this is wrapped with SET_KEY because I need to set the “uploadUrl” to the Firebase upload destination. So just copy the formula i use above, replacing “myprojectname” with your Firebase project name for the upload Url.
- Upload Files. Pretty simple. Use ‘Post’ method and the FileListObj variable as ‘Files to upload’.
You should get a ‘Complete’ success output. Go to your Firebase Storage console (refresh it) and see your file is there now.
If you get any errors:
- Double-check your upload URL is correct with the name of your Firebase project with .appspot.com appended to it.
- Make sure your File List Object variable schema is exactly as the one i showed above (remember size must be ‘number’ type, and uploadUrl must be ‘any text’ type)
- If necessary, use an Alert function to verify/display that your File List Object variable is complete at index [0].
Note - to display Firebase Storage image files in Appgyver you must add “?alt=media” to the image URL.
For example if your upload Url is:
https://firebasestorage.googleapis.com/v0/b/myprojectname.appspot.com/o/myImage.jpg
Then the URL you would set in your Image component to display this image would be:
https://firebasestorage.googleapis.com/v0/b/myprojectname.appspot.com/o/myImage.jpg?alt=media
Hope this helps.