Skip to content

ODataService CreateMedia

Create Media action is used to create one or multiple OData Media Entities with Media Link (an OData EntityType with HasStream="true" attribute).

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

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

ODataService CreateMedia Properties

Property Type Required
Headers object No
Media object[] Yes
Properties object No
RequestOptions RequestOptions No
Target Target Yes
_Type const Yes

Headers

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

  • type: object

Media

If the array contains multiple items, multiple Media Entities will be created.

  • type: object[]

The actual value of the media. Should be in this format {"content":binary, "contentType":string}.


Properties

A list of the target entity's property names and values in key/value pairs format. Complex property type is supported.

  • type: object

RequestOptions

Options for processing of data requests


Target


_Type

  • type: const

The value of this property must be:

"Action.Type.ODataService.CreateMedia"

Action Result

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

The success ActionResult of this action is a JS array of OData media entities. 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):

<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>
...
...
<EntitySet Name="Products" EntityType="MyODataModel.Product"/>

Note: Each entity can only have a single associated media stream. With this action, you can create "Product" entity and at the same time upload a media file (e.g. an image) to it.

CreateMedia with documents from Attachment control

{
  "_Type": "Action.Type.ODataService.CreateMedia",
  "Target": {
    "Service": "/MyMDKApp/Services/MyOData.service",
    "EntitySet": "Products"
  },
  "Properties": {
    "ID": "#Control:IDCtrl/#Value",
    "Name": "#Control:NameCtrl/#Value",
    "Price": "#Control:PriceCtrl/#Value"
  },
  "Media": "#Control:Attachment/#Value"
}

CreateMedia with Signature image from Signature control

{
  "_Type": "Action.Type.ODataService.CreateMedia",
  "Target": {
    "Service": "/MyMDKApp/Services/MyOData.service",
    "EntitySet": "Products"
  },
  "Properties": {
    "ID": "#Control:IDCtrl/#Value",
    "Name": "#Control:NameCtrl/#Value",
    "Price": "#Control:PriceCtrl/#Value",
  },
  "Media": ["#Control:SignatureCell/#Value"]
}