0

i am trying to implement file upload while being connected to a web-socket in spring boot server.

i am converting every file uploaded to base64 format and then sending it in form of json..

but whenever i exceed a limit of 1 mb it gives me an error about handshake failed..

here is my relevant spring code websocket configuration file

@Configuration      
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer{
    
    
        @Override
        public void registerStompEndpoints(StompEndpointRegistry registry) {
            registry.addEndpoint("/fellowGenius").setAllowedOrigins("*")
            .addInterceptors(new HttpSessionHandshakeInterceptor()).withSockJS()
            .setStreamBytesLimit(104857600*3)
            .setHttpMessageCacheSize(100000)
            .setDisconnectDelay(200 * 1000);;
        }
    
        @Override
        public void configureMessageBroker(MessageBrokerRegistry config) {
            config.enableSimpleBroker("/inbox/");
        }
}

here is my controller code

@Controller
@CrossOrigin(origins = "http://localhost:4200")
public class WebSocketController {
        
    // sending files inside the meeting
    @MessageMapping("/sendFile/{bookingId}")
    @SendTo("/inbox/MeetingChat/{bookingId}")
    public String onRecievedFile(@DestinationVariable String bookingId,@Payload String file) {
        return file;
    }
}

here is my most relevant typescript code written in angular framework

    sendFile(message: MessageModel, bookingId: string) {
        let data = JSON.stringify({
            message: message
        });
        this.ws.send('/sendChat/' + bookingId, { }, data);
    }

I am getting handshake failure error ...

ERROR 14721 --- [io-5000-exec-10] o.s.w.s.s.s.DefaultHandshakeHandler : Handshake failed due to invalid Upgrade header: null

  • There is a lot of info in this other question: https://stackoverflow.com/questions/11080112/large-file-upload-with-websocket To my knowledge Spring uses STOMP as underlying protocol for websockets communication. For binary data you should use the low level API. – aballaci Jul 04 '20 at 20:00
  • @ArmandoBallaci thanks for the suggestion – fellowGenius Technologies Jul 04 '20 at 20:16

0 Answers0