On 20/01/18 10:07,
rmhay...@gmail.com wrote:
> Can someone explain what JavaScript should be in the server to catch the
> 'download' command and return the specified file? What should the
> "socket.on(???, downloadFile);" look like? What's the correct way to
> return the file so the client browser correctly saves it?
It looks much the same as what it does to display your index page, but
instead of setting "Content-Type: text/html" and dumping HTML, it sets
"Content-Type: application/octet-stream" and dumps binary data.
You haven't told us what HTTP server you're using, so it's a little
difficult to say exactly how you do it. One commonly used one for this
task is Express…
https://expressjs.com/en/starter/hello-world.html gives an example of
doing more or less what you've done… if you were to modify that front
page with a hyperlink, the extra code would look like this:
app.get('/mydata.csv', function (req, res) {
res.set('Content-Type', 'application/octet-stream');
res.send('your CSV data');
});
--
Stuart Longland (aka Redhatter, VK4MSL)
I haven't lost my mind...
...it's backed up on a tape somewhere.