#All credit goes to Jackoby, this is me learning powershell by writting and understanding his code myself
function DropBox-Upload {
[CmdletBinding()]
param (
[Parameter (Mandatory = $True, ValueFromPipeline = $True)]
[Alias("f")]
[string]$SourceFilePath
)
$DropBoxAccessToken = "" #THE TOKEN ONLY LASTS UP TO FOUR HOURS! PLEASE REPLACE WHEN USING
$outputfile = Split-Path $SourceFilePath -leaf
$TargetFilePath = "/$outputfile"
$arg = '{"path": "' + $TargetFilePath + '"mode": "add", "autorename": true, "mute": false}'
$auth = "Bearer " + $DropBoxAccessToken
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $auth)
$headers.Add("Dropbox-API-Arg", $arg)
$headers.Add("Content-Type", 'application/octet-stream')
Invoke-RestMethod -Uri https://content.dropboxapi.com/2/files/upload -Method Post -InFile $SourceFilePath -Headers $headers
}
The last line throws an exception, saying the arg is not valid json?