# Update-ERPMedia Cmdlet to update the Media Resource of an existing streamable entity with a given media file. ## Syntax ```powershell Update-ERPMedia [[-EntitySet] ] [[-File] ]] [[-Keys] ] [[-ContentType] ]] [] ``` ## Parameters | Type | Name | Description | Optional | |----------------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------| | String | EntitySet | The 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, ) | no | | Hashtable / PSObject | Keys | The reference properties for the entity beeing updated | no | | String | File | Path to the file to upload | no | | String | ContentType | Specifies 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' …) | yes | ## Return type **Bool**:\ **\$true** ← on success.\ **\$false** ← on failure. Exception/ErrorMessage can be accessed using [\$Error]().\ If the cmdlet fails due to error responses returned by the ERP system, the \$Error variable provides a [WebRequestException]() . ## Remarks The Cmdlet 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 Cmdlet 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. ## Examples In the following example we are using the public OData Services () for demonstration purposes: **Updating the Media Resource of a Media Link Entry (MLE)** ```powershell 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' ``` :::{note} 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** ```powershell 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" ``` **Error handling, analyze the** [WebRequestException]() **why the Media Resource could not be updated, by using \$Error** ```powershell Connect-Erp -Service "https://services.odata.org/V3/(S(o2bnti0dqsoaosxxnt5pci1q))/OData/OData.svc/" $result = Update-ERPMedia -EntitySet "Advertisements" -Keys @{"ID"=[guid]"f89dee73-af9f-4cd4-b330-db93c25ff3c7"} -File "C:\Temp\MyPictures\GT220 Change Proposal.png" if(-not $result){ $Error[0].Exception.StatusCode #413 $Error[0].Exception.Message #"Request Entity Too Large" } ```