ODataService UploadMedia¶
Upload Media action is used to upload one or multiple OData Media Entities. Action are also applicable to this action.
ODataService UploadMedia Properties¶
Property | Type | Required |
---|---|---|
Headers | object |
No |
Media | object[] |
Yes |
RequestOptions | RequestOptions | No |
Target | LinkQueryTarget | 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}.
RequestOptions¶
Options for processing of data requests.
- type: RequestOptions
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: LinkQueryTarget
_Type¶
- type:
const
The value of this property must be:
"Action.Type.ODataService.UploadMedia"
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¶
"Image" EntityType is a Media Entity.
<EntityType Name="Image" HasStream="true">
<Key>
<PropertyRef Name="ID"/>
</Key>
<Property Name="ID" Type="Edm.String" Nullable="false"/>
<Property Name="Name" Type="Edm.String" Nullable="false"/>
</EntityType>
...
...
<EntitySet Name="Image" EntityType="MyODataModel.Image"/>
Note: Uploads media, it replaces if it has any existing media. UploadMedia action is for MediaEntity. UploadStream action is for normal Entity, if the property type is Edm.Stream.
UploadMedia from Attachment control¶
{
"_Type": "Action.Type.ODataService.UploadMedia",
"Target": {
"Service": "/MyMDKApp/Services/MyOData.service",
"EntitySet": "Images",
"ReadLink": "{@odata.readLink}"
},
"Media":"#Control:Attachment/#Value",
"ActionResult": { "_Name": "OData" },
"OnSuccess": "/MyMDKApp/Actions/ClosePage.action",
"OnFailure": "/MyMDKApp/Rules/Failure.js"
}
{
"_Type": "Action.Type.ODataService.UploadMedia",
"Target": {
"Service": "/MyMDKApp/Services/MyOData.service",
"EntitySet": "Images",
"QueryOptions": "$filter=ID eq 1234"
},
"Media":"#Control:Attachment/#Value",
"ActionResult": { "_Name": "OData" },
"OnSuccess": "/MyMDKApp/Actions/ClosePage.action",
"OnFailure": "/MyMDKApp/Rules/Failure.js"
}