Created
April 7, 2016 19:52
-
-
Save laurentkempe/9e71a307e1d216d17e5adf1589e51c5e 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
<# | |
.SYNOPSIS | |
This is a Powershell script to upload a file to DropBox using their REST API. | |
.DESCRIPTION | |
This Powershell script will upload file to DropBox using their REST API with the parameters you provide. | |
.PARAMETER SourceFilePath | |
The path of the file to upload. | |
.PARAMETER TargetFilePath | |
The path of the file on DropBox. | |
.ENV PARAMETER DropBoxAccessToken | |
The DropBox access token. | |
#> | |
Param( | |
[Parameter(Mandatory=$true)] | |
[string]$SourceFilePath, | |
[Parameter(Mandatory=$true)] | |
[string]$TargetFilePath | |
) | |
$arg = '{ "path": "' + $TargetFilePath + '", "mode": "add", "autorename": true, "mute": false }' | |
$authorization = "Bearer " + (get-item env:DropBoxAccessToken).Value | |
$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 |
Thanks. It worked for me.
My only issue was that I first had to create a "Dropbox app", and issue rights to it, to create the access token.
You need to assign rights (files.content.write) before you create the token, as the rights are stored inside the token !
Hope this helps.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It happens to me too