This is a demo which shows how upload a file to a websocket server. Follow the next steps:
- Select a file which will be sent to server.
- Then press connect. If connection is successful a message will show you are connected to server.
- Press upload button and when file has been transferred you will see a message confirming this.
Upload File Demo
Select filevar ws; function connectChatServer() { ws = new WebSocket("wss://esegece.com:5415"); ws.binaryType = "arraybuffer"; ws.onopen = function() { alert("Connected.") }; ws.onmessage = function(evt) { alert(evt.msg); }; ws.onclose = function() { alert("Connection is closed..."); }; ws.onerror = function(e) { alert(e.msg); } } function sendFile() { var file = document.getElementById('filename').files[0]; var reader = new FileReader(); var rawData = new ArrayBuffer(); reader.loadend = function() { } reader.onload = function(e) { rawData = e.target.result; ws.send(rawData); alert("the File has been transferred.") } reader.readAsArrayBuffer(file); }
