2

The frameworks i'm using are AngularJS(client-side) and Sitebricks(server-side). I want to return a list of objects into json and make the client download that json by prompting the user where he wants to save the file.

I accept all kind of propositions. Cheers in advance.

Tek
  • 1,178
  • 1
  • 12
  • 22
  • http://stackoverflow.com/questions/7288814/download-a-file-from-nodejs-server – Stav Geffen Sep 24 '13 at 12:43
  • well , what bothers me is that there is an actual file on the server. I cannot create any files on the server so i cannot send files. I guess i can just create a stream and send the string data from the server and on the client to read the stream. Thanks – Tek Sep 24 '13 at 12:47

2 Answers2

3

It sounds like you want to create the file in the browser, and save it to the user's local machine. One method is presented here, but it doesn't work in IE Javascript: Create and save file

Here's a fiddle: http://jsfiddle.net/vUdyD/

$(function() {
  function exportToCsv() {
        var myCsv = "Col1,Col2,Col3\nval1,val2,val3";

        window.open('data:text/csv;charset=utf-8,' + escape(myCsv));
    }

    var button = document.getElementById('b');
    button.addEventListener('click', exportToCsv);
});
Community
  • 1
  • 1
Jason
  • 15,915
  • 3
  • 48
  • 72
1

You could use the HTML5 download attribute. It is not perfect and browser support

<!-- will download as "expenses.pdf" -->
<a href="/files/adlafjlxjewfasd89asd8f.pdf" download="expenses.pdf">Download Your Expense    Report</a>

Demo: http://davidwalsh.name/download-attribute

Support: http://caniuse.com/#feat=download

arhea
  • 454
  • 2
  • 5
  • 1
    Well here again is the situation with having a file on the server. but i can't create any files on the server.. so i can't pass file to the client. – Tek Sep 24 '13 at 13:00