javascript - Sending files to the browser with AngularJS, WebAPI, not triggering download? -


pulling out hair on this.

i have request via angular:

x.deliverfile = function(fileid) {   $http({     method: "get",     url: mybase + "services/deliverfile?fileid=" + fileid,     headers: myheaders   }).success(function(data, status, headers, config) {     console.log(data);   }); }; 

and in web api:

if fileinfo.exists   dim result new httpresponsemessage(httpstatuscode.ok)   result     .content = new streamcontent(new filestream(fileinfo.fullname, filemode.open, fileaccess.read))     .content.headers.contentdisposition = new headers.contentdispositionheadervalue("attachment")     .content.headers.contentdisposition.filename = fileinfo.name     .content.headers.contenttype = new headers.mediatypeheadervalue("application/octet-stream")    end   return result    else     return request.createresponse(httpstatuscode.notfound) end if 

i've done httphandlers many times, missing web api.

i'm able see bytes in via console.log(data);

i can't figure out how browser trigger download.

i read post here: download file asp.net web api method using angularjs

i'm having trouble accepting "accepted answer", there must way trigger download in cross-browser compliant manner.

you need use filesaver.js , can this:

x.deliverfile = function(fileid) {   $http({     method: "get",     url: mybase + "services/deliverfile?fileid=" + fileid,     headers: myheaders   }).success(function(data, status, headers, config) {     var blob = new blob(data, {type: "text/plain;charset=utf-8"});     saveas(blob, "filename.txt");   }); }; 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -