Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting downloads to work between angularjs and express.js

I can get the raw data of the file that I am requesting, but I can't get the browser to serve the file to the user. Do I need to use iframes?

   //Client code
   download_file: function (path, callback) {
       $http.post('/download/client_file', {path:path}).
           success(function(data, status, headers, config) {
                console.log(data); //this contains the raw data of the res.download 
                                   //from the server.
           });
   }

   //server code
   res.download(file); // the path is proper
like image 337
The_Brink Avatar asked Nov 03 '22 08:11

The_Brink


1 Answers

I used the code below in my services file for downloading items and it worked great. I got it from http://filamentgroup.com/lab/jquery_plugin_for_requesting_ajax_like_file_downloads/

$('<form action="'+ url +'" method="'+ ('post') +'">'+inputs+'</form>')
               .appendTo('body').submit().remove();
like image 83
The_Brink Avatar answered Nov 09 '22 02:11

The_Brink