I am trying to achieve following. But, I have no idea as I am a beginner to firebase.
- User is trying to upload a post with image
- Image is selected from web browser
- When user clicks save button, I am uploading the selected image to firbase storage and getting the download URL.
- Inserting the post data with download url to firestore database.
Till this, I have completed. Now, I need to resize the uploaded image.
For that, I am trying to use Cloud Functions, whenever a new entry is added to firestore database, I am calling a Cloud fountion, which can access the download URL of the image, using this download URL, I need to resize image. Please help.
Please let me know, if there are having any better approach to achieve this. (I know there should be :P )
Edit 1
Thank you Frank for your reply.
I have the below cloud function, which will be called for every post is inserted. I am getting the download URL of the image from the eventSnapshot. I need to resize the image in that location. Please help.
exports.resizeImage = functions.firestore
.document('posts/{postId}')
.onCreate(event => {
var eventSnapshot = event.data.data();
//In this eventSnapshot I am getting the document, and I can get the download URL from the document
});
I have analyzed the example to create thumbnail, but for that, I need the
storage object, and it will be called only when the storage object is changed. But, I need to do the thumbnail creation when the onWrite called in firestore.
exports.generateThumbnail = functions.storage.object().onChange((event) => {
// File and directory paths.
const filePath = event.data.name;
});
Please let me know, how to do the image resize operation, by detecting the onWrite in firestore and using downLoadURL.