Skip to content

ODataService DownloadMedia

Download Media action is used to download the associated media stream of a Media Entity (an OData EntityType with HasStream="true" attribute) to the device.

This action is not supported in ChangeSet.

Note: This action cannot be used to download data stream of OData property with "Edm.Stream" type of an EntityType. Please use Action.Type.ODataService.DownloadStream instead.

All the properties defined under Action are applicable to this action.

ODataService DownloadMedia Properties

Property Type Required
DownloadOptions DownloadOptions No
Headers object No
RequestOptions RequestOptions No
Target LinkQueryTarget Yes
_Type const Yes

DownloadOptions

Options for download media request


Headers

Custom headers to be included as part of the request to the OData Service in key/value pair format

  • type: object

RequestOptions

Options for processing of data requests


Target

This action can only be executed on a single entity. therefore the Target specifier must be configured to return only 1 entity, otherwise this action will fail


_Type

  • type: const

The value of this property must be:

"Action.Type.ODataService.DownloadMedia"

Action Result

Refer to the MDK Guide to understand what an action result is.

The success ActionResult of this action is the stream data of the downloaded media. The failure ActionResult is an error message.


Examples

OData Media entity

"Product" EntityType is a Media Entity and it has an associated media stream (could be a product image) that can be downloaded:

<EntityType Name="Product" HasStream="true">
  <Key>
    <PropertyRef Name="ID"/>
  </Key>
  <Property Name="ID" Type="Edm.String" Nullable="false"/>
  <Property Name="Name" Type="Edm.String" Nullable="false"/>
  <Property Name="Price" Type="Edm.Decimal" Nullable="false"/>
</EntityType>

Note: Each entity can only have a single associated media stream.

Query Options

{
  "_Type": "Action.Type.ODataService.DownloadMedia",
  "Target": {
    "Service": "/MyMDKApp/Services/MyOData.service",
    "EntitySet": "Images",
    "QueryOptions": "$filter=id eq {id}"
  }
}
{
  "_Type": "Action.Type.ODataService.DownloadMedia",
  "Target": {
    "Service": "/MyMDKApp/Services/MyOData.service",
    "EntitySet": "Images",
    "ReadLink": "{@odata.readLink}"
  }
}

DownloadOptions

{
  "_Type": "Action.Type.ODataService.DownloadMedia",
  "Target": {
    "Service": "/MyMDKApp/Services/MyOData.service",
    "EntitySet": "Images",
    "ReadLink": "{@odata.readLink}"
  },
  "DownloadOptions": {
    "WriteToFilePath": "/MyMDKApp/Rules/GetFilePathName.js"
  }
}