react-chat-widget icon indicating copy to clipboard operation
react-chat-widget copied to clipboard

how to send file attachment or send image ?

Open achrefothmani opened this issue 4 years ago • 2 comments

achrefothmani avatar Apr 19 '20 11:04 achrefothmani

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('![this is picture](https://github.com/nice.png)');

Here21 avatar Apr 23 '20 07:04 Here21

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" />);
});

SirBenedick avatar Jun 04 '20 10:06 SirBenedick