Hi,
Hope you’re doing well.
I have a post that contains text content and an image into it. Now, I have to implement the Edit Post Feature in which I wanna change the text content and add more images into it. The update of text change is working with PostRepository.editPost();
API but adding more images into it is not working.
How to implement this change?
Best,
Aamir Shehzad
Hello @aamir.shehzad , We need additional information from you to investigate this issue:
- The platform and version you are using.
- The full code related to the issue you are encountering.
This will help us better understand the problem and provide a more accurate solution. Thank you
Hi @SocialPlus_Support,
I’m using React Native for both iOS and Android with TypeScript. For adding media, I’m using metadata when creating the post. The first time, if I create only post including images, it works fine. Then I’m implementing edit post feature, and the images are not being attached to the exiting post.
Let me show you my code:
const handleEditPost = async () => {
try {
const updatedPost = {
data: {
text: text,
}
};
if (imageUri.length > 0) {
const uploadPromises = imageUri.map(async (element) => {
console.log("image ==== >", element);
const { uri } = element;
console.log("uri ==== >", uri);
const data = new FormData();
data.append('files', { uri, name: 'post_image', type: 'image/jpeg' });
const { data: image } = await FileRepository.uploadImage(data);
return image[0];
});
await Promise.all(uploadPromises)
.then((imageArray) => {
console.log('All images uploaded successfully:', imageArray);
updatedPost.metadata = {
image: {
data: imageArray
},
};
return;
})
.catch((error) => {
console.error('Error uploading images:', error.message);
});
}
const { data: post } = await PostRepository.editPost(postId, updatedPost);
console.log(`Edit Success! Updated post ${JSON.stringify(post)}`);
} catch (error) {
console.log("Faild to edit post due to ", error);
} finally {
onClose();
setIsLoading(false);
}
};
I’m happy to share more information if required.
Best,
Hello @mustafa , Based on our team’s review, we recommend referring to this documentation for implementation: Edit a Post. Specifically, use attachments instead of metadata for adding images to the post.
Please let us know if you need further assistance.