Hi Harri, I have the tutorial document (markdown) and images ready. Where should I send it?
Can I store images (from my phone) in the firestore database? Is this possible? Thanks a lot.
Not in the database itself. Images are not a data type allowed by Firestore.
However, you can save the image to Google photos and save the path in the Firestore database. See Google photos API for info.
The data types allowed by Firestore are:
- Null values
- Boolean values
- Integer and floating-point values, sorted in numerical order
- Date values
- Text string values
- Byte values
- Firestore references
- Geographical point values
- Array values
- Map values
Thanks a lot for your prompt reply. Unfortunately I couldnt find a way to upload any image from my phone to any database via api with appgyver… Only https://docs.appgyver.com/tutorials/uploading-files method is working but this very very slow or not working at all on live app. If you can suggest any other method, I really appreciate…
I have not used it, but from the Google photos API reference, I see that an AppGyver integrated data resource could be configured to POST a media item (photo, video) to a user photos library (remember there is no storage limit in Google Photos if the resolution adheres to Google’s cap)
I wrote a better looking and, hopefully, better explained Firestore REST API direct integration tutorial.
If there is any question or error , or something is not clear, please drop a note here.
@Eduardo_Jaramillo Thanks for putting this guide together! QQ for you…
The create record works fine when I test the schema in the Data Resource API configurator and in the web preview app. In both instances the new test record shows up in my firestore DB.
But when I test the create record logic node in the mobile preview app it doesn’t work properly. Looking at the debugger the http request goes through fine but it doesn’t actually create a record in firestore (currently I have security rules off so I don’t believe that’s the issue).
Any idea why it works on web but not on mobile?
I have tried the same logic on both, web and mobile (android) preview app and it does create the new record, so I am not sure what’s happening. If you send me a snapshot of your create record logic node and data resource (post) setup I will gladly take a look at it.
I’m not either. I’m using the iOS preview app so perhaps that has something to do with it.
Thanks for giving it a look over @Eduardo_Jaramillo !
Here’s the logic node flow & node itself
I’ve also tried the above create record after executing dismiss initial view node in a different place in the nav stack and also removed the check device token/notification nodes.
Here’s the binding for the create record node:
Here’s the POST setup:
Here’s the Schema:
Here’s the successful test record:
I don’t find anything wrong with the setup.
The only thing that comes to my mind that might be a problem is the Firestore authorization, if you have application restrictions (found on the API Keys in the Google Cloud console):
because Firestore OAuth 2.0 tokens are different for android apps, web and ios apps.
Thanks Eduardo! I double checked and I have no restrictions, though, I don’t think I have the API key anywhere in AppGyver. The google API was automatically created through Firebase where I setup separate apps for iOS, Android, & Web.
I’m not sure what the issue is. I think I’m just going to use the Real Time Database which writes just fine on the iOS preview app for the time being.
EDIT: Resolved but saved answer for posterity – see below
I’ve followed your instructions exactly (at least, I think so!) but every time I run a Test on the GET COLLECTION, I see the following error:
"Error: TypeError: Failed to fetch. Does the server allow CORS?status: undefined
Resource settings for Get collection (GET)
Resource URL: https://firestore.googleapis.com/v1
Relative path: /projects/[redacted]/databases/(default)/documents/./test
What am I doing wrong? I have my Rules set to test mode (“allow read, write: if true;”) so I don’t think I should need to set up authorization?
After spending a ridiculous amount of time troubleshooting, here’s the answer: For whatever reason it’s very important to Appgyver that the forward slash between the Base URL and the Relative URL be put in the Resource URL field of the Base tab (i.e., “
https://firestore.googleapis.com/v1/”). This is shown incorrectly in the tutorial (see screenshot under Data Resource Setup: Base). So moving that one slash from the beginning of the Relative URL (in GET tab) to the end of the Resource URL (in Base tab) solved my problem.
I recommend replacing that screenshot in the tutorial – or better yet updating this part of the Appgyver interface to concatenate better and allow both placements of the forward slash as long as they’re consistent!
Sorry for the late answer, but was away.
Appgyver does not require the slash at the end of the url on the base tab.
The after mentioned error is the result of a wrong full URL (base+relative path), as having both an slash at the end of the base and another one at the beginning of the relative path, so there will be two successive slashes on the full path.
@Eduardo_Jaramillo I think I see what you mean – AppGyver assumes a forward slash at the end of Base URL, whether you put it there or not? Still, the point stands that you can’t start your Relative URL with a slash or else it will throw an error (even if you did not end your Base URL with a slash), so I still think the tutorial needs to be updated to reflect that.
I do have another question that’s hopefully less nitpicky! I’m having some trouble understanding schemas. In my Firestore database I have documents with several different schemas (e.g. one document with two boolean fields and a number field, another document with 5 text fields). How does this map onto Appgyver data sources? Do I need to create a schema that includes every field that every one of my documents might contain? Do I need to set separate data sources for each separate type of document? Or is there a better way to do this?
Thanks for your help,
It works either way:
I have both configurations in the same app and both work. In the first data resource configuration the slash is at the end of the Resource URL, and in the second is in the Relative path. AppGyver makes no assumption about the slash placement; what is important is that there is only one slash, because de full path string is the concatenation of the Resource URL and the Relative path.
As far as I know, your schema in AppGyver has to include all the fields on the database, or the documents that don’t adhere to the schema will not be retrieved. In your example, the schema has to have the two boolean, the number and the five text fields.
Saw your comment about you being able to implement Firebase auth using OAuth2. Can you please assist by showing how you did using AppGyver Data Configurator? I mean how to get the authorization code and then using it to get the access Token. Also, what AppGyver URI to use for the redirect call back from the authorization server.
Worth mentioning that, for test purposes, i got Postman to work nicely with the Firebase OAuth2.
You are a lifesaver @Eduardo_Jaramillo.
I have had many sleepless nights on this matter.
I will implement this right away.
I have a question though. This question is from the perspective of someone used to SQL database.
I have multiple tables (Apologies for my SQL grammar) for my database. These include; User, Sales, Products, Customers, etc. These tables have a many-to-many relationship and I want to recreate them in Firestore’s database.
I would love to know how I can start to think about them.
Here are my questions:
Should I create multiple collections where each collection represent each table? or should I make each table a Sub-collection of the User table?
How do I go about relating them to each other?
When I connect them to my Appgyver data Configurator, should I make them different resources or a single resource?
The paradigm of SQL and noSQL databases is so different that would suggest another approach if you are to implement your application in Firestore.
The design of a noSQL database does not start from the data, but from the info you want to retrieve from it. In other words, first you think of what the users need to retrive and how is it to be presented, and then you think about the database structure.
Suggested basic reading: https://www.mongodb.com/nosql-explained/data-modeling#:~:text=NoSQL%20databases%20are%20designed%20to,the%20beginning%20of%20a%20schema.
How to Design Schema for Your NoSQL Database? - DATAVERSITY