0

I am using the below code to download the file returned from WCF REST service (file is returned as stream). This code is working fine for text file but the files such as excel and pdf are getting corrupted and they are not getting opened after download.

Can anyone suggest work around for this issue..

$.ajax({
            url: 'http://localhost:53471/testServices.svc/GetFile?ID=10',
            type: 'GET',               
            cache: false,
            contentType: "application/octet-stream",
            success: function (data,json,status) {                    
                var blob = new Blob([data]);
                var link = document.createElement('a');
                link.href = window.URL.createObjectURL(blob);
                link.download = "Test document.pdf";
                link.click();

            },
            error: function (data) {
                alert('Some error Occurred!');
            }
        });
Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44
user17274
  • 11
  • 2
  • 6

0 Answers0