I'm currently using Stream Chat React to build a chat application, and I'm facing an issue when trying to delete a single attachment from a message containing multiple attachments. I can successfully delete the entire message using the methods provided in the Stream Chat React documentation, but I cannot find a way to delete just one attachment from the message.
Here's what I have tried so far:
I've checked the Stream Chat React documentation for any methods specifically designed to remove single attachments, but I couldn't find any. I tried modifying the message object by removing the desired attachment and then updating the message, but it didn't seem to work.
Tried method to delete the attachment
// Delete File await channel.deleteFile(fileURL);
// Delete Image await channel.deleteImage(imageURL);
URL - https://getstream.io/chat/docs/react/file_uploads/?language=javascript
ERROR - The file not found this but we trying to access the image or file with the same URL it is accessable.
I would appreciate any guidance on how to delete a single attachment from a message with multiple attachments in Stream Chat React. Is there a built-in method or workaround to achieve this functionality? If anyone has faced a similar issue or can point me in the right direction, that would be extremely helpful. Thank you!
thanks for using Stream!
In the use-case that you have a delete is not really an option due to you not wanting to delete the entire message. Instead what you can do, is update the message to not include the attachment anymore. We even have a helpful function to do a partialUpdateMessage
.
With that, you can filter the attachments and can use the imageUrl
property to select the desired one.
Here's what this looks like in code:
client.partialUpdateMessage(message.id, {
set: { attachments: message.attachments.filter((m) => m.image_url !== imageUrlToRemove) },
});
In case you have more questions, always feel free to reach out!