Hello, welcome to another video of The Complete Angular Course.
Hello, welcome to another video of The Complete Angular Course.
Firebase Storage
Go to the Firebase Console.
It is currently allowing us to read and write data to the storage if we are logged in.
Since we want everyone to be able to read all the posts, remove the read parameter from the allow statement and add another allow statement to allow everyone to read. Then publish the rules.
Uploading Files to the Storage
Let’s see how we can add files to the storage.
1) Go to the Create Post component TypeScript file and define the function.
Instead of placing images in a static folder call Post1, we want to place the post image in a specific folder for each post using the document id of the new post.
If we go to the Firebase Console and click on the Files tab, we will see a folder call Post. If we go inside, there is another folder, and inside that folder, is the file for our image.
Storing the Post in Firestore
5) Lastly, add the onComplete callback function.
import { FirebaseTSApp } from 'firebasets/firebasetsApp/firebaseTSApp';
The next thing we need to do is to close the dialog when the upload is complete.
import { MatDialogRef } from '@angular/material/dialog';
constructor(private dialog: MatDialogRef<CreatePostComponent>) { }
If we run the app and create a post, the data will be uploaded to Storage and then to Firestore.
Fixing Errors
1) Create another function call uploadPost().
Go to the onPostClick() function and use the if statement to check if there is an selected image file.
If we run the app and try to post an empty post, nothing will happen.