ODataService CreateRelatedMedia¶
Create Related Media
action is used to create a media entity(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).
All the properties defined under Action are applicable to this action.
ODataService CreateRelatedMedia Properties¶
Property | Type | Required |
---|---|---|
Headers | object |
No |
Media | object[] |
Yes |
ParentLink | LinkItem | 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}.
ParentLink¶
Parent entity information including navigation property name, entitySet name and readLink or queryOptions.
- type: LinkItem
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
- type: RequestOptions
Target¶
- type: Target
_Type¶
- type:
const
The value of this property must be:
"Action.Type.ODataService.CreateRelatedMedia"
Action Result¶
Refer to the MDK Guide to understand what an action result is.
The success ActionResult of this action is a JS array containing the OData readLink of the created entities. The failure ActionResult is an error message.
Examples¶
OData Related Media entity¶
"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"
}