Created
September 6, 2019 08:25
-
-
Save jhorsman/a74347767f64bcd9f4bee9922c72fd67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage examples | |
# .\Set-DxAddon.ps1 -Url "http://server:83" -Path addon.zip | |
# .\Set-DxAddon.ps1 -Path addon.zip | |
param ( | |
[parameter(Mandatory=$false, HelpMessage="Tridion DX Add-on service URL. Defaults to 'http://localhost:83'")] | |
[string] $Url = "http://localhost:83", | |
[parameter(Mandatory=$true, HelpMessage="Path to to the add-on.")] | |
[string] $Path | |
) | |
$ErrorActionPreference = "Stop" | |
if(-not (Test-Path $Path)) | |
{ | |
Write-Error "File '$Path' does not exist" | |
} | |
$filename = Split-Path $Path -Leaf | |
$fileBytes = [System.IO.File]::ReadAllBytes($Path); | |
$fileEnc = [System.Text.Encoding]::GetEncoding('ISO-8859-1').GetString($fileBytes); | |
$boundary = [System.Guid]::NewGuid().ToString(); | |
$LF = "`r`n"; | |
$bodyLines = ( | |
"--$boundary", | |
"Content-Disposition: form-data; name=`"File`"; filename=`"$filename`"", | |
"Content-Type: application/x-zip-compressed$LF", | |
$fileEnc, | |
"--$boundary--$LF" | |
) -join $LF | |
$postUrl = $Url + "/addon/api/v1/addons" | |
Invoke-RestMethod -Uri $postUrl -Method Post -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $bodyLines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment