Skip to content

ODataService CreateMedia

Create Media action is used to create an Entity with Media Link (an OData EntityType with HasStream="true" attribute). This action is not supported in ChangeSet. It is supported in OData v2 (offline and online) and v4 (online only) services.

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.

The properties defined in Action are also applicable to this action.

ODataService CreateMedia Properties

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

Headers

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

  • type: object

Media

  • type: object[]

All items must be of the type: object with following properties:

Property Type Required

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 equal to:

"Action.Type.ODataService.CreateMedia"

Action Result

The ActionResult of this action is a JS array of OData media entities.


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"]
}