I have records in firestore that refer to the names of files I have stored in cloudstorage. Before I allow a record to be written, I need to first check that the file has been uploadedto cloudstorage.
I realize that the files could later be removed, but at the time of writing the record I need to check that they have been uploaded so as to limit errors.
I only need to check for one file per one request. I tried using exists
and refer to my bucket but I couldn't get it to work.
CodePudding user response:
You cannot access data from Firebase Storage in security rules of Firestore. You can try either of these:
- Make sure the add document function runs after the file has been uploaded (by awaiting promise in JS)
- Use Firebase Storage Triggers which will run a function when a file has been uploaded and then add the document from Cloud function. If you are using this method you can remove write access from users so only the Cloud function can add documents when that object is uploaded.