0

I am trying to use BusinessObject RESTful API to download a generated (pdf or xls) document.

I am using the following request:

$.ajax({
 url: server + "/biprws/raylight/v1/documents/" + documentId,
 type: "GET",
 contentType: "application/xml",
 dataType: "text",
 headers: {"X-SAP-LogonToken": token, "Accept": "application/pdf" },

 success: function(mypdf) {
    // some content to execute
 } 
});

I receive this data as a response:

%PDF-1.7
%äãÏÒ
5 0 obj
<</Length 6 0 R/Filter/FlateDecode>>
//data
//data
//data
%%EOF

I first assumed that it was a base64 content, so in order to allow the users to download the file, I added these lines in the success function:

var uriContent = "data:application/pdf; base64," + encodeURIComponent(mypdf);
var newWindow=window.open(uriContent, 'generated');

But all I have is an ERR_INVALID_URL, or a failure while opening the generated file when I remove "base64" from the uriContent.

Does anyone have any idea how I could use data response? I went here but it wasn't helful. Thank you!

. bjorge .

Community
  • 1
  • 1
bjorge
  • 179
  • 1
  • 1
  • 12
  • I'm afraid, nothing much can be done from client-side i.e. JavaScript. The server side coding has to be changed so that a url link is generated (pointing to the pdf file) and sent as part of the response. The user can download the pdf from the url link. – kcak11 Feb 19 '14 at 11:46

2 Answers2

0

Nothing much can be done from client-side i.e. JavaScript.

The server side coding has to be changed so that a url link is generated (pointing to the pdf file) and sent as part of the response. The user can download the pdf from the url link.

kcak11
  • 832
  • 7
  • 19
  • I knew I couldn't create a file on the server, but I thought I could generate a file using its contents. Unfortunately, I can't implement a click event which target to my file because it has no physical existence on the server, it is generated on-the-fly by BusinessObject. Thank you anyway ! . bjorge . – bjorge Feb 24 '14 at 14:03
0

You cannot create file using javascript, JavaScript doesn't have access to writing files as this would be a huge security risk to say the least.

To achieve your functionality, you can implement click event which target to your required file and it will ask about save that file to user.

Kapil Kshirsagar
  • 282
  • 1
  • 4
  • 19
  • I knew I couldn't create a file on the server, but I thought I could generate a file using its contents. Unfortunately, I can't implement a click event which target to my file because it has no physical existence on the server, it is generated on-the-fly by BusinessObject. Thank you anyway ! . bjorge . – bjorge Feb 24 '14 at 14:02