0

my team has been stumped on this one. We are using Business Intelligence REST service to get a PDF report from the server using jQuery GET ajax call . It returns the bytes of the PDF (looks like gibberish) but when I create a file in a SharePoint library from the bytes the PDF won't open, it says it is corrupt. If I write server c# code, I can convert the response from the REST query no problem into a PDF.

I've been able to successfully save uploaded PDFs and PDFs with a straight up *.pdf URL as well. There's something different with the format of the response.

Response is object Blob type=application/pdf

Response as XML looks like (base64?) JVBERi0xLjcKJeTjz9IKNCAwIG9iago8PC9MZW5ndGggMyAwIFIvRmlsdGVyL0ZsYXRlRGVjb2Rl... Raw response looks like pdf gibbeish (like if you open a PDF in notepad)

How can I save or open this as working PDF? Ultimately I need to upload it into SharePoint, but even just opening it in the browser as PDF would be great.

This code returns Blob

$.ajax(
        {
            url:"MYBUSINTELLIGENCESERVER/raylight/v1/documents/"+ docID +"/",
            type: "GET",
            dataType: "binary",

            processData: false,
            headers:
            {
                "Accept": "application/pdf",
                "X-SAP-LogonToken":secToken
            },                
            success: function(result)
            {

                uploadFile(result);

            }
        })

The uploadFile has about 20 variations that all fail. Code of no use. I imagine we're missing something basic, but can't figure it out.

Please help if you've ever successfully saved a business intelligence PDF with JavaScript!

This isn't a duplicate because none of the suggested duplicate answers worked. I found the answer on my own.

  • I haven't ever tried business-intelligence you mentioned, but if you are downloading the binary file, make sure you understand correctly the binary encoding that it may have gone through. If the response is in base64 string type, you first need to decode it into binary and then save as a file, at the end upload it to the SharePoint server you've mentioned. I'm not sure, but there might be some byte order problem you need to look into. Try with hex/bin editor to see carefully the returning response. – viz Jan 17 '18 at 19:43
  • This isn't a duplicate. This is specific to Business Intelligence, which is not addressed in dupes. Was hoping to provide answer for Business Intelligence community as there are no samples I could find anywhere on the web, but cannot. – Tomas Gendron Jan 22 '18 at 21:03

0 Answers0