Cmdlet to update the Media Resource of an existing streamable entity with a given media file.

 Update-ERPMedia [[-EntitySet] <String>] [[-File] <String>]] [[-Keys] <Object>] [[-ContentType] <String>]] [<CommonParameters>]

Type Name Description Optional
StringEntitySetThe EntitySet name where the Media Link Entity is located.
It is also possible to specify additional namespaces or the whole url (e.g MaterialService/Materials, http://localhost:8080/PGS/ERP/MaterialService/Materials)
Hashtable / PsObject Keys The reference properties for the entity beeing updatedno
StringFilePath to the file to uploadno
StringContentTypeSpecifies the content type of the web request.
If no content type is provided, the cmdlet sets the content type depending on the file extension. (e.g .txt ⇒ 'text/plain', .pdf ⇒ 'application/pdf' …)

$true ← on success.
$false ← on failure with an additional property 'Error' containing the Exception/ErrorMessage.

The commandlet is used to update the Media Resource of an existing Media Link Entry (MLE) by uploading the specified file.

The ContentType is used to specify the nature of the file currently being handled. With the appropriate content type the web browser can open the file with the proper extension/plugin.

  • If no content type is set the commandlet will determine the content type depending on the file type.
  • If the content type contains text (e.g text/plain, text/html…) as type or json , xml (e.g application/json, application/xml…) as subtype, then the content of the file is uploaded to the server as UTF-8 Encoded text.

In the following example we are using the public OData Services (http://services.odata.org) for demonstration purposes:

Updating the Media Resource of a Media Link Entry (MLE)

Invoke-WebRequest -Uri 'https://randompokemon.com/sprites/normal/143.gif' -OutFile 'C:\Temp\TestMedia.gif'

Connect-Erp -Service "http://services.odata.org/V4/OData/(S(du4oaehbpzqh2eznhygi1xkg))/OData.svc"
Update-ERPMedia -EntitySet "Advertisements" -Keys @{ID=[Guid]'f89dee73-af9f-4cd4-b330-db93c25ff3c7'} -File 'C:\Temp\TestMedia.gif'

The cmdlet automatically detects the ContentType of the file to be 'image/gif'. The browser is able to use this information and directly show the image.
You can test the updated Media Resouce by clicking here.

In the following examples we are using a custom plugin for the powerGateServer:

Updating the Media Resource of a Media Link Entry (MLE) with specific ConentType and download it again

Invoke-WebRequest -Uri 'https://randompokemon.com/sprites/normal/6.gif' -OutFile 'C:\Temp\TestMedia.gif'

Connect-Erp -Service "http://localhost:8080/powerGate.Tests/TestService"
Update-ERPMedia -EntitySet "Files" -Keys @{"Id"=2} -File "C:\Temp\TestMedia.gif" -ContentType 'image/x-xbitmap'

Get-ERPMEdia -EntitySet "Files" -Keys @{Id=2} -File "C:\Temp\TestMedia_2.gif"