I'm trying to upload files using Powershell to a folder inside our company Dropbox. I'm using a function I googled somewhere (I don't have the URL at hand, sorry about that):
function Upload-FileToDropbox {
Param(
[Parameter(Mandatory=$true)]
[string]$SourceFilePath,
[Parameter(Mandatory=$true)]
[string]$TargetFilePath,
[Parameter(Mandatory=$true)]
[string]$DropBoxAccessToken
)
$arg = '{ "path": "' + $TargetFilePath + '", "mode": "add", "autorename": true, "mute": false }'
$authorization = "Bearer $DropBoxAccessToken"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $authorization)
$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
}For this script, I've created a new team app with Permission type Team member file access, and requested an access token. For the parameters in this function, I'm using something like this:
$SourceFilePath = "C:\TEMP\test.txt"
$TargetFilePath = "/IT/test.txt"
However, when I try to upload a file, I'm getting the following error:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
I tried running the Invoke-RestMethod manually, creating the headers by hand, but I get the same error over and over again. What am I missing?
Thank you for the help!