react-chat-widget
react-chat-widget copied to clipboard
how to send file attachment or send image ?
file not support yet, but you can use link syntax of markdown.
image also can use markdown syntax, like below:
// file
addResponseMessage('[this is file](https://github.com/nice.tar)');
// image
addResponseMessage('');
If you want to send an image from your server to the web app you can do this by base64 encoding the image and rendering it as a custom component.
Here an example on how to encode an image with node.js, send it via a socket to the client and render the image:
// Node.js
fs.readFile(pathToImage, (err, data) => {
this.socket.emit("chat-image", "data:image/png;base64," + data.toString("base64"));
});
// react-chat-widget
socket.on("chat-image", (data) => {
renderCustomComponent(() => <img src={data} height="300" width="300" />);
});