Hacker News new | ask | show | jobs
by adpowers 5261 days ago
I made almost exactly the same thing a few months ago: http://www.transfury.com/

The server is written in node.js and it uses socket.io to do the transfers. I think it only works in Chrome because I didn't bother getting the drag-and-drop working with anything else. Actually, it seems to be broken in the current dev channel of Chrome. I announced it back in September:

https://plus.google.com/116396240707733722472/posts/d9ydb8o2...

2 comments

Interesting! It's funny how we both chose the same arbitrary chunk size :)
Heh. Well, mine wasn't completely arbitrary. If I remember correctly I was trying to trade off server CPU usage with memory usage. One chunk at a time is buffered on the server, so I wanted to keep it small enough that I could have a bunch of ongoing transfers on my puny t1.micro. However, too small of a chunk size resulted in too many roundtrips and lots of CPU load on the server. I settled on this value because I was able to pump a couple megabytes per second through it using one stream, which seemed reasonable.

Also: in further testing, it looks like Safari works with the drag and drop, but not the uploading. I purposely disabled all socket.io transfer types except web sockets in order to encourage adoption of modern browsers. Unfortunately, since I used such bleeding edge, unstandardized technology (drag and drop, file API, and web sockets), the browsers have changed and broken my implementation, each in a slightly different way, such that none of them work end to end anymore.

If anyone cares, I found out what the problem was. Chrome updated to a new version of the web socket standard back in version 15 or so. I wasn't aware of the change and so didn't update my version of socket.io which supports the new standard, thus an incompatibility. It should work now.

This just goes to show that you have to be vigilant if you are building sites with the latest and greatest, as they are still under development and likely to change out from under you.

Couldn't you just connect the uploader's POST to the downloader's GET request instead of using websockets?
This seems to be more of a streaming upload/download. Node just basically pipes along the chunks from the serving peer through the websockets.

I'm pretty sure that if you just "connect the uploader's POST to the downloader's GET" then the Node server would have to buffer the entire file from the submitter before sending it to the clients.

> I'm pretty sure that if you just "connect the uploader's POST to the downloader's GET" then the Node server would have to buffer the entire file from the submitter before sending it to the clients.

Not at all. Use stream.pipe(). I've done it countless times and it works really well.