rstoyanchev / spring-websocket-portfolio

736 stars 443 forks source link

Streaming data of a file in topic with WebSocketMessageBroker #77

Open guibernardi opened 4 years ago

guibernardi commented 4 years ago

Hi Rossen. Sorry for bothering you here.

I'm trying to send a file through a topic using websockets.

Actually I was converting the file to base64 and send as a dataUri to the topic like this:

messagingTemplate.convertAndSendToUser(purchaseReport.getSessionId(),
                        "/queue/greetings",
                        DATA_APPLICATION_ZIP_BASE_64.concat(getDocumentsAsBase64(fileWriter.write(report).toPath())),
                        createHeaders(purchaseReport.getSessionId()));

The problem is that when the file is too large the base64 obviously is extremely. So I'm trying to Streaming the file in the topic using SimpMessageSendingOperations, but until now still didn't work.

Do you have any tip or material that I could follow? I was trying to coding as the same concept of Streaming data using RestTemplate or a regular http request.

Thanks in advance.