Skip to content

ODataService CreateRelatedMedia

Create Related Media action is used to create a media enity(an OData EntityType with HasStream="true" attribute). The new media entity is linked to its parent entity(an entity has a navigation property linking to the new media entity).

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

ODataService CreateRelatedMedia Properties

Property Type Required
Headers object Optional
Media string Required
ParentLink LinkItem 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

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

  • type: string

Parent entity information including navigation property name, entitySet name and readLink or queryOptions.


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.CreateRelatedMedia"

Action Result

The ActionResult of this action is a JS array containing the OData readLink of the created entities.


Examples

"Image" EntityType is a Media Entity and it has an associated media stream:

<EntityType Name="Image" HasStream="true">
<Key>
<PropertyRef Name="id"/>
</Key>
<Property Name="id" Type="Edm.Int64" Nullable="false"/>
<Property Name="label" Type="Edm.String" Nullable="true"/>
<Property Name="created" Type="Edm.Date" Nullable="true"/>
<Property Name="updated" Type="Edm.Date" Nullable="true"/>
<NavigationProperty Name="artist" Type="Self.Artist"/>
</EntityType>

Parent EntityType "Artist" has a navigation property linking to "Image":

<EntityType Name="Artist">
<Key>
<PropertyRef Name="id"/>
</Key>
<Property Name="id" Type="Edm.Int64" Nullable="false"/>
<Property Name="firstName" Type="Edm.String" Nullable="false"/>
<Property Name="lastName" Type="Edm.String" Nullable="false"/>
<Property Name="dateOfBirth" Type="Edm.Date" Nullable="true"/>
<NavigationProperty Name="images" Type="Collection(Self.Image)"/>
</EntityType>

Note: Each entity can only have a single associated media stream. With this action, you can create an "Image" entity and at the same time upload a media file to it. The new "Image" entity is linked to an existed "Artist" entity by its navigation property "images".

CreateRelatedMedia

{
  "_Type": "Action.Type.ODataService.CreateRelatedMedia",
  "Target": {
    "Service": "/MyMDKApp/Services/MyOData.service",
    "EntitySet": "Images"
  },
  "Properties": {
    "ObjectKey": "#Control:ObjectKey/#Value",
    "FileName": "#Control:FileName/#Value"
  },
  "ParentLink": {
    "Property": "images",
    "Target": {
      "EntitySet": "Artists",
      "ReadLink": "{@odata.readLink}"
    }
  },
  "Media":"#Control:Attachment/#Value"
}

CreateRelatedMedia without Properties

{
  "_Type": "Action.Type.ODataService.CreateRelatedMedia",
  "Target": {
    "Service": "/MyMDKApp/Services/MyOData.service",
    "EntitySet": "Images"
  },
  "ParentLink": {
    "Property": "images",
    "Target": {
      "EntitySet": "Artists",
      "ReadLink": "{@odata.readLink}"
    }
  },
  "Media": "#CurrentPage/#Control:Attachment/#Value"
}