Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
Showing results for 
Search instead for 
Did you mean: 

A year ago, I encountered a challenge working with a third party document repository system that does not have a real RESTful Webservice.

The challenge was the third party system uploads PDF files that needs to be attached in SAP via GOS. There is no established interface between an old system to the SAP system but luckily, the old system can still do java script.

To make it worse, the SAP system did not have NW Gateway and the customer will not pay for NW Gateway for this requirement. So, implementing official RESTful SDK is not possible

So, the solution is to cheat the Webservice to be able to send a file. Another problem is that it cannot send a complex file.

So the solution I implemented was:

1. I have created a unofficial webservice in the SAP system via SICF and custom handlers. If you are not familiar with this -> view Pseudo-RESTful API in SAP without SAP NW Gateway . The tutorial will show you how to create an unofficial RESTful service.

2. On the Third Party system side, I created a custom Webservice consumer via Javascript.

var postUrl = "http://servername:8000/zrest_2/zfilepost?xblnr="
  + entry.xblnr + "&lifnr=" + entry.lifnr + "&sp_id=" +;
  url: postUrl,
  type: "POST",
  data: filestring,
  success: function(data){

I am using the standard Jquery API

<script type="text/javascript" src=""></script>

What it does is call the webservice created in SAP.

The first two steps are not really too trivial. There are a lot of discussions about this before. The challenge now is how to send a file across that framework and the solution is base64.

What is Base64? Base64 is an encoding scheme that converts binary format to radix 64. MIME specification lists Base64 as one of the binary to text scheme. Base64 has its advantages and disadvantages that I will not discuss here.

So, moving on with the steps.

3. The next step is to convert binary to base64 that will in turn be send via JS in step 2. In Javascript, you need to convert the file to Base64

if(this.status == 200){
                    var blob = new Blob([this.response],{type:"application/pdf"});
                    reader.onloadend = function(){
                        var result = reader.result;
                        var bin = convertDataURIToBinary(result);
function convertDataURIToBinary(dataURI) {
                var BASE64_MARKER = ';base64,';
                var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
                var base64 = dataURI.substring(base64Index);
                var raw = window.atob(base64);
                var rawLength = raw.length;
                var array = new Uint8Array(new ArrayBuffer(rawLength));
                for(i = 0; i < rawLength; i++) {
                  array[i] = raw.charCodeAt(i);
                return array;

The convertDataURIToBinary converts the file to base64 file text file.

4. Lastly, we use ABAP FM SSFC_BASE64_DECODE to convert base64 back to binary file using the lv_string as the file converted in the Javascript

  lv_string = iv_base64.
  SPLIT iv_base64
     AT ','
     INTO lv_header
*  rv_output = cl_http_utility=>if_http_utility~decode_base64( encoded = lv_string ).
      b64data = lv_string
      bindata = rv_output
      OTHERS  = 8.

5. Lastly, we attach the file to GOS via SO_OBJECT_INSERT. This has been well documented and you can search a lot of documents to support this.

I hope this helps!

1 Comment