user5444681
user5444681

Reputation:

How to send images base64 encoded via WebSocket? (Getting close event 1006)

I am trying to send a file to a server. I have a fixed message format which looks like this:

var msg = {
    'msgtype': <number>,
    //additional data specific to the msgtype
};

For images it looks like this:

var msg = {
    'msgtype': 9,
    'id': 42, // to which group this image belongs to
    'blob': 'BASE 64 encoded image string'
};

When reading files and sending it, it crashes. The server does not receive any data. When sending a little file like this: Test image it works. After examining the error messages I found the close reason: 1006.

Another idea would be, to directly send the binary data, but that would break my message schema. Also: I don't know how to assign the binary stream on the webserver to the given id. The only solution with this approach would be to send the id first and treating the rest as data.

edit: I tested it with a static string. I can put up to 8153 characters in the blob string. If there's more it crashes.

Upvotes: 0

Views: 1417

Answers (1)

user5444681
user5444681

Reputation:

The issue was the message size. I found out, that I can set it on server side (Java) by running:

session.setMaxTextMessageBufferSize(200000);

Upvotes: 1

Related Questions