0

I have used angular-file-saver to download a file in my application but I'm stuck with,how i can implement the same while downloading from the server and saving the file in the existing form.

My controller.js

vm.download = function(data){
 vm.ProjectId = workspaceService.getSelectedWorkSpaceDeal().id;
 manageRFPService.getFieldData(vm.ProjectId).then(function(data){
 vm.downloading = data;
 var down = new Blob([vm.downloading],{ type: 'text/plain;charset=utf-8' });
 FileSaver.saveAs(down,'documentname.txt');
 }); };

the response in the data contains a file name but the file is not downloading with its extension rather just an response is getting downloaded in text form.

my Html

<td><a ng-href=" " ng-click="vm.download( )">{{uploading.documentname}}</a>

If the above getting response is similar for multiple object display

HKI345
  • 293
  • 3
  • 8
  • 23
  • i can see in the marked existing question response type is "responseType: 'blob' "....instead of using as such can we use a blob as creating object instance above....because im using the same get response for other instances in application too...? @georgeawg – HKI345 May 09 '17 at 05:35
  • [A Blob object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) can be used wherever a URL is used: `href`, `src`, `window.open`,etc. To manipulate it in JavaScript, use the [FileReader API](https://developer.mozilla.org/en-US/docs/Web/API/FileReader) to convert it to an arraybuffer, base64, or text. – georgeawg May 09 '17 at 20:09
  • Thank you..:)...i was able to solve that..@georgeawg – HKI345 May 10 '17 at 13:57

0 Answers0