Skip to content

Instantly share code, notes, and snippets.

@laurentkempe
Created April 7, 2016 19:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laurentkempe/9e71a307e1d216d17e5adf1589e51c5e to your computer and use it in GitHub Desktop.
Save laurentkempe/9e71a307e1d216d17e5adf1589e51c5e to your computer and use it in GitHub Desktop.
<#
.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
@Vadimkr1
Copy link

Hi, when I started the script, accured the error "Invoke-RestMethod : The remote server returned an error: (400) Bad Request.".

@gblr
Copy link

gblr commented Aug 9, 2017

It happens to me too

@GeoDerp
Copy link

GeoDerp commented Oct 28, 2017

same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment