cancel
Showing results for 
Search instead for 
Did you mean: 

Error trying to export Excel sheet to repository

Former Member
0 Kudos

Hi All,

I´m on BO 4.1 SP5 trying to export an excel sheet,  using javascript, to the repository.

I´m getting an HTTP 500 error.

Following is my code

   bodie = '--10f3211b-66e8-4b14-93ec-b11ec5c19a43-41d3c84c-d157-4377-aba9-41353b9a4dfe \

Content-Disposition: form-data; name="attachmentInfos"\

Content-Type: application/xml\

<spreadsheet>\

    <name>//lambari/pmae-d/corporativo/usuarios.xls</name>\

    <folderId>234707</folderId>\

</spreadsheet>\

--10f3211b-66e8-4b14-93ec-b11ec5c19a43-41d3c84c-d157-4377-aba9-41353b9a4dfe\

Content-Disposition: form-data; name="attachmentContent"\

Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\

... Excel 2007 document as a binary stream...\

--10f3211b-66e8-4b14-93ec-b11ec5c19a43-41d3c84c-d157-4377-aba9-41353b9a4dfe--'

// ==================================================================================================

  var docum = new XMLHttpRequest();

  // url da consulta

var url = 'http://vrt0568.bndes.net:6405/biprws/raylight/v1/spreadsheets';

  docum.open('POST', url, false);

  docum.setRequestHeader('X-PINGARUNER', 'pingpong');

  docum.setRequestHeader('Content-Type', 'multipart/form-data');

  docum.setRequestHeader('Accept', 'application/xml');

  docum.setRequestHeader('X-SAP-LogonToken', tokenDec);

  docum.send(bodie);

Am I using the right url ?

Cheers,

Rogerio

Accepted Solutions (1)

Accepted Solutions (1)

daniel_paulsen
Active Contributor
0 Kudos

Hi Rogerio,

your URL looks fine.  I think the issue is with the Body where you have text in-line with the binary content of the file.

To get it working for myself, I broke the body into 3 parts, the header, the file stream and the footer.

I converted the header and footer into byte arrays and then concatenated the 3 parts together as my request stream.

the below is C# code, but hopefully it demonstrates what I'm talking about:

               //write the request body to the stream
                byte[] reqBodyStart = System.Text.Encoding.UTF8.GetBytes(bodyStart);
                byte[] reqBodyEnd = System.Text.Encoding.UTF8.GetBytes(bodyEnd);

                             
                Stream reqStream = myWebRequest.GetRequestStream();
                reqStream.Write(reqBodyStart, 0, reqBodyStart.Length);
              

                //add file to stream
                reqStream.Write(filestream, 0, filestream.Length);
                reqStream.Write(reqBodyEnd, 0, reqBodyEnd.Length);
                reqStream.Close();

Dan

Former Member
0 Kudos

Hi Dan,

at least I know what´s happening. But I don´t know how to translate your code to Javascript.

Did you convert the three parts to byte , concatenate them and then write it back as a string ?

Cheers,

Rogerio

daniel_paulsen
Active Contributor
0 Kudos

Hi Rogerio

Yes, add everything together as a continuous array of bytes.  Don't convert back to string but rather search on google for how to upload binary data using XMLHttpRequest.

Dan

Former Member
0 Kudos

Thanks a lot Dan !!!!

former_member197386
Active Contributor
0 Kudos

Hi Rogerio,

If you could share with the community how you figured out this point using Javascript, I'm sure it will be very worthwhile for many Raylight lovers!

Best regards,

Anthony

Former Member
0 Kudos

Hi Anthony,

I´ve just seen your reply today..

In fact I´really don´t test the approach.

What I was intending to do is to alter the the personal DP from a WEBI Document so I was thinking in schedule the report to the file system, upload the excel and then modify the DP for a report.

But I think it´s a very demandinfg task because of the size of the Excel file.

So I think about schedulin the report to BO´s server , get the ID of this scheduled report and then change the DP.

But I didnt try this approach yet.

I´m considfering wrtie a document about uing the RESTFUL API with Javascript next year.

Merry Christas,

Rogerio

former_member197386
Active Contributor
0 Kudos

Ok for the blog post, write it down yo your new year resolution list

Merry Christmas too!

Anthony

Answers (0)