Last active
May 11, 2020 04:36
-
-
Save mul1sh/bfb56e5ba7ffef58975e9f24c161761c to your computer and use it in GitHub Desktop.
Post Image Update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When the app restarts or when loading the posts from firestore do this | |
// import the ImageUpload class like you are doing in the posts screen | |
// check if a post is missing a picture | |
if (post.picture.uri == undefined || post.picture.uri == "" ) { | |
// if a post is missing a picture then get the picture locally via the post id | |
const picture = await ImageUpload.getLocalPic(post.Id); | |
// get the pic preview too | |
const preview = await ImageUpload.preview(picture); | |
// then upload the image again but pass undefined as the post id because we don't want to save the picure again | |
const url = await ImageUpload.upload(picture, undefined); | |
// then update the the post in firebase using the post id | |
const ref = Firebase | |
.storage | |
.ref() | |
.child(post.id); | |
// update the post object | |
const post: Post = { | |
id: post.id, | |
url, | |
preview, | |
// set the rest of the params | |
}; | |
const snapshot = await ref.put(post); | |
// finally delete the image locally | |
await ImageUpload.deletePictureLocally(post.id); | |
// and then you will be done :) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment