Ask HN: Is it feasible to serve up a remote file for a file download link?

1 points by codingclaws ↗ HN
Say you want to have links on your site that download files, but the files are on a remote server relative to the web server.

If the web server has to first download the file from the remote server and only then send it to the browser, then it seems like there would be a browser stall while the web server downloaded the file behind the scenes. Basically, a double download with no user feedback during the first download.

Instead, I implemented it with file streams. There's an SSH file stream and then I pipe that into the HTTP response to the browser. The only problem with this is that the download speed it really bad. Do SSH file streams kill download speed? Or was it just the SSH file stream lib that I used?

Is there another way to do this?

Is it even possible to seamlessly do something like this? Or is my only option to use local files and ditch the remote server?

5 comments

[ 2.6 ms ] story [ 23.5 ms ] thread
If it’s not media (I don’t know why you’re streaming) then CloudFlare considers 512MB small-enough to CDN for free.
That’s a clever solution, but you’re an idiot for trying it when there are simpler and more obvious solutions. Just put an HTTP daemon on that other server, point a domain at it, and link to the files there.
I need to run back-end code when the download link is clicked. Does this solution still hold?
Unless the action is idempotent, it shouldn’t be a link. It should be a button in a form instead. The form can POST to your main server which can do whatever work is required and then send back a 302 response to redirect the user to the file on the other server. You probably don’t want search engines clicking on it and triggering whatever work you are doing on the server; using a form prevents that.