I've build a webapp that can send images. For small pictures everything works fine. But as soon as it gets a little bigger ~1000x1000px, socket.io does not emit. It does not even state an error. It just does not send the image.
This is what my Object looks like:
chatBlock = {
username: "",
message: "",
date: new Date(),
file: null,
imgWidth: 0,
imgHeight: 0,
};
and thats how I send it:
socket.emit('msgSend', chatBlock);
So actually pretty basic, but as soon as the image (named file in the object) gets to big, it does not send it.
Socket.io has a message size limit: see option maxHttpBufferSize
in the docs at https://socket.io/docs/v4/server-options/#maxhttpbuffersize .
You can increase this limit, but keep in mind that parsing images as JSON is not very efficient. In the long term, consider uploading the images separately - a common solution is to use HTTP POST, obtain the uploaded URL, and send that to the recipient instead. This is more complex, but avoids the message size problem entirely, as file uploads can be of any size and still be streamed in an efficient manner.