All Kony Fabric Posts

Byte Range Serving - Downloading a large binary in chunks

Ajay Bhat - Dec 23, 2016 - Sync

Kony MobileFabric enabled support for binaries as part of its Object Services release in 7.0. As part of the 7.2 MobileFabric release, this feature is further enhanced with Byte Range Serving, which allows chunking of binary downloads. Abhay Hegde details out this feature.

Byte Range Serving is a technique where a client can request a specific portion of Large Binary file that is present on the backend. This technique efficiently uses the network bandwidth by allowing user to download the binary in chunks ranging over multiple requests to the server.

This feature is especially useful in downloading large media files such as *.mp3, *mp4, *mkv etc. Let’s understand how.

Suppose the server doesn’t support Byte Serving, and you as a user would like to download a video file from the backend. Since the server lacks this feature, you cannot view or play the video until the entire file is downloaded. Still worse, if your network connectivity goes down or disconnects during the download, then you will have to re-initiate the download process all over again! Now that’s a bummer!

Interested in knowing further? Read on...

Here's a bird's eye view of the entire feature.

Byte Serving Block diagram

  • This looks interesting. How do I try out this feature?
    • If you are on cloud , approach
    • If you are on On-Premise , install KonyMobileFabric 7.2
  • Any caveats that I should know before trying?
    • Only HTTP GET is supported, meaning you can only download in chunks
    • This is applicable only for SAP backend, meaning you can download binaries present in SAP backend.
    • Kony SDK support is available only in offline scenario. You can build apps and incorporate this feature as a Sync service.

Now that things are in perspective, let us see how we can build this service.

Creating Byte Serving Service

  • After you have installed Kony MobileFabric 7.2 and started the server, login to your MobileFabric console by entering your email and password.

MobileFabric login

  • After logging in, create a new MF App, by clicking on Apps and then Add New

Screenshot for adding new MobileFabric app

  • Once you are prompted with App creation page, you will have to create an Identity service. This service provides security to your App by providing you claims token which enables you to connect to the backend.

Create Identity Service


Click on Identity in the App creation page and provide the details. Please note Type of Identity should be Kony SAP Gateway as this feature is tied to a SAP backend.

Once you have entered all the details, make sure the credentials are valid by clicking on Test Login

Save the service.

Creating an Object Service
  • Now that Identity service is in place, let us move on to next task, i.e., Creating Object Service. Object service provides you capabilities to create Data and Relationship Models.
  • To create an Object Service , click on Object Service link in the same App Creation page as before:

Object Service Creation

Upon clicking on Configure New, in the subsequent page provide a name to your Object Service. Under Endpoint Type, select SAP Business Adaptor. Choose the Security Level based on your requirement.Object Service Creation Details

Object Service Details


Under "Select authentication service", choose "Use Existing Identity Provider" and select the identity service you have configured earlier. Provide user credentials and click on "Save and Continue."

Configuring Object Services

You should have a page which looks something like this.

Object Services app page

In subsequent steps, we will cover how to create a Data Model and Relationship Model. For the purpose of blog, we will import existing backend objects using “Generate”.

Clicking on Generate icon will prompt you a list of Backend Objects that are present in your backend. Select the backend object you would like to download. It will typically have binary or media objects present in it.

Selecting SAP objects for generation

  • Using the 'Generate' option, CRUD operations will automatically mapped to your media objects as shown in the “Configure” window.

Generating objects


  • Click on getBinary since that’s the operation which is tied to this feature.

Choose getBinary


  • getBinary

getBinary mapped to backend object


As you can see from the highlighted text, getBinary is mapped to a backed object

Publishing your Service

Now that we have configured a web service, let’s go ahead and publish it.

To publish a service, you will have to create an Environment where your Server is currently running.

  • To create an environment, click on Environments icon on the left side pane of the Mobile Fabric Console and then click on Add New icon

Create new environment


Create New Environment Options

  • Provide any name in Environment Name space.
  • Under Server tab , enter the URL on which your server is running
  • Click on Test Connection and later Save
  • Go back to your App page, and click on Publish.

Publish the app

  • Select the name of the Environment you just created and hit on Next which you should take you to the publish page.
  • Hit Save and Publish
  • Once your service is published, you are ready to test it. In order to test it, you need the URL of the service which you can use it in a REST client.
  • To know the URL , login to your admin console, whichis generally<IP>:<PORT>/admin
  • Upon logging in, click on Object Services on the left side pane

Object Service view in Admin Page

  • Select the media object under App Data Model Objects drop down corresponding to your web service.
  • In the subsequent page, copy the URL from the highlighted area below.

getBinary URL

Testing Your Object Service

Now that we have the URL it’s time to test your service.

  • Launch your favorite REST client (POSTman , REST etc)
  • Change the HTTP method to GET and paste the URL that you have copied above
  • Append name=<name_of_binary_file_you_want_to_download_>&type=bytes to the URL .

For example, if http://<IP>:<PORT>/services/data/v1/<App_Name>/binary/media is the URL , your finalURL after appending query parameters should be: 


Please note:-We are querying here based on the name of the file. Query parameter might vary based your backend object parameters that we exposed.

  • Headers
    • There are 2 key headers that you need to pass along with request , namely X-Kony-Authorization and Range header
    • X-Kony-Authorization header – to get the value of this header you need to make a POSTcall to your identity service which will return the claims-token
    • Range :- Range header values is according to the HTTP spec and is of the format bytes=start-end

To wrap it up, this is how your final REST call will look like:

REST call with headers

Upon successful REST call, your response headers should be similar to this:

Response Headers in case of success

Content-Length is the chunk size that was returned in Bytes. Content-Range is the bytes requested and total length of the media object.

In case of off-line download(Kony Sync), HTTP status code will be 206.

Using Kony MobileFabric SDK to develop a mobile app using this feature

As mentioned in the “Caveats” list above, as of 7.2 release, SDK support for Byte Range Serving is only available for Kony Sync service. Please refer to Mobile Fabric Sync to know more about Kony’s Sync offerings.

Below is a sample JavaScript code snippet to download binary in chunks:

function downloadBinaryWithChunking() {

var downloadConfig = {};
downloadConfig.ChunkSize = 100000;
var pkTable = {}; = "BIN1234";
konysync.getBinary("media", "url", pkTable, downloadConfig, downloadBinarySCB, downloadBinaryECB);

To know more about the SDK APIs, please refer to Large Binary Object

Hope this was helpful to get you started. If you have any questions or face any issues, please reach out to Kony Community Forums.