Reputation: 5056
Let's say we have a chat app and we want users to be able to send images.
Would it be appropriate to convert the image to Base64 in order to send the image through the websocket? A few posts I was reading mentioned this wouldn't be a good use of websockets, so would it be better to have an endpoint for images, and tie that image to the message on upload completion?
Totally new to websockets, so I'm not really sure what to do here.
Upvotes: 2
Views: 699
Reputation: 2097
You can use XMLHttpRequest for file upload and then send the link along with the data through websocket. Uploading file through websocket will require extra code at the server side to convert the received data to files.
Also check http://binaryjs.com/ BinaryJS is bidrectional realtime binary data with binary websockets
As of today, XMLHttpRequest is the standard most of the companies are using for the file upload, some of the reasons for choosing HTTP are support for caching, gzipping, authentication, firewall, browser compatibility and horizontal scaling.
Upvotes: 1