2
votes

This is sort of a theoretical question, however, I need to add file sharing capabilities to my web socket powered chat application. I could use a service like Amazon S3 to upload a file to share by posting a link to the file, but that involves the uploading of a file that may already be accessible over the local network (sharing a file between co-workers for example).

So I had the idea that it might be possible to somehow tunnel the upload/download/transfer through the already existing web socket connection. However, I don't know enough about HTTP file transfer to know the next step of how to implement it. Is there a limitation to web sockets that would prevent this from being possible?

I'm using Ruby and EventMachine for my current web socket implementation. If you were able to provide a high level overview to get me started, that would be very much appreciated.

2
That would still involve one end uploading the file to the other end of the web socket connection (the web server) and the other end downloading the file from the other end of its web socket connection (again, the web server).David Schwartz
@David yeah, I guess you're right. But it would still avoid storing the file on the server (which I guess might be the advantage that I'm trying to achieve?)Andrew
Actually, the real advantage that i'm hoping this would achieve is that a user can "share a file" with the rest of the users in the chat room before the file has actually been uploaded and doesn't start uploading until someone actually requests the file. For example, if a file took 30 minutes to upload, the chat room would not know about the file until that upload finished, then the users would also have to wait for that file to download, however, if the upload/download were happening simultaneously it could potentially increase the overall time spent transferring the file.Andrew
While you're using ruby / eventmachine, and this example is with javascript on the server side, it does show how files can be sent through websockets. github.com/einaros/ws/tree/master/examples/fileapieinaros

2 Answers

2
votes

Here's an example of a project that uses only Web Sockets and the javascript File API for transferring files: http://www.github.com/thirtysixthspan/waterunderice

1
votes

To allow files to be shared without the need to upload it to the server, (i.e Coworkers) you can now use the WebRTC DataChannel API, to create a peer to peer connection.