Skip to content

OData Media Binding

Info

The feature described in this topic is meant for application targeting Mobile Development Kit 6.1 or newer.

This feature is not available in older releases.

This topic describes about binding OData media stream to your UI controls. It allows you to easily bind the stream entity or property to your UI controls to render as images or open any media via the Open Document action.

It support both OData media entity (OData Entity Set with HasStream=true) or OData stream property (OData property with Edm.Stream type).

The syntax comes in 3 different segments:

/<ServicePath>/<EntityReadLink>/<$value or PropertyName>

Note

In Offline OData use case, it is highly recommended that you set "AutomaticallyRetrievesStreams" to true for all OData Media defining requests. Without it, the images are downloaded to the offline store on demand which significantly increases the rendering time.

Caching

Mobile Development Kit will automatically cache any media downloaded via this binding method.

If your back end supports and returns media ETag as part of the response payload for each of the media stream, the app will be using the ETag to automatically manage and update the cache if the media resources were updated in your back end.

For more details regarding ETag in OData, you can check the following OData specifications:

Note: For Offline OData, the ETag information will only be updated after the database is synced with the latest data from the back end.

If your OData service does not support ETag for media resources, then the app can't help to manage and update your cache for you, as an alternative you can use the ClientAPI.deleteODataCacheImages API to clear all cached images e.g. You can call this API during the launch of your app to always clear all cached images.

Examples

Binding OData Media Entity

Assuming you have an Entity Set called Picture which is a media entity type i.e. HasStream=true declared in the Entity Set, and you are in a page which as a binding context that resolve {@odata.readLink} to Picture(123).

The syntax to display one of the entity for this entity set is as follows:

{
  "ObjectCell": {
    "DetailImage": "/MyApp/Services/MyODataService.service/Picture(123)/$value"
  }
}

Binding OData Stream Property

Assuming you have an Entity Set called Product with the following properties:

  • ProductThumbnail with type Edm.Stream
  • ProductImage with type Edm.Stream
  • ProductImageMimeType with type String that contains the mime-type of the image

And you are in a page which as a binding context that resolve {@odata.readLink} to Product(456).

The syntax to display these images would be:

{
  "ObjectCell": {
    "DetailImage": "/MyApp/Services/MyODataService.service/{@odata.readLink}/ProductThumbnail"
  }
}

Or via Open Document action:

{
  "_Type": "Action.Type.OpenDocument",
  "Path": "/MyApp/Services/MyODataService.service/{@odata.readLink}/ProductImage",
  "MimeType" : "/{@odata.readLink}/ProductImageMimeType"
}

Note

You can bind non-image media with Open Document action too as long as you provide the correct mime-type to the MimeType property of the action.

In version 6.2 onwards, if your OData Service returns @odata.mediaContentType in the response, then you do not need to provide the MimeType property of the action.


Last update: April 8, 2022