Public/MIT/Invoke-MITFileUpload.ps1
function Invoke-MITFileUpload { [CmdletBinding()] param ( [Parameter(Mandatory)] [string]$Id, [Parameter(Mandatory)] [string]$FilePath ) # This function will only work on version 6 or later. if ($PSVersionTable.PSVersion.Major -lt 6) { throw "Invoke-MITFileUpload requires PowerShell 6 or later" } $hostname = $Script:MITHostname $token = $Script:MITToken $resource = "/folders/$Id/files" $Uri = "https://$hostname/api/v1/$Resource" $Headers = @{ Accept = "application/json" Authorization = "Bearer $token" } $form = @{ comments = "Uploaded via REST API" hashtype = 'sha-1' hash = (Get-FileHash -Algorithm 'SHA1' -Path $FilePath).Hash file = Get-Item -Path $FilePath } $response = Invoke-RestMethod -Method 'Post' -Uri $Uri -Headers $Headers -Form $form -TransferEncoding chunked Write-Output $response } |