cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you new to Dropbox? Our Newcomers group is the perfect place to learn the basics, find out more here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Corrupted Files using API in PowerShell

Corrupted Files using API in PowerShell

Shushu
New member | Level 2

Hi All. 

   I'm using the below code in powershell but for some reason the files get corrupted once they arrived to dropbox folder.  If i transfer the file manually there's no issues, the error it's present only using the dropbox API, do you have and idea why this happened? 

 

Regards. 

 

 

$SourceFilePath = "PathSource"

$TargetFilePath = "PathDestination"

 

 

$arg = '{ "path": "' + $TargetFilePath + '", "mode": "add", "autorename": true, "mute": false }'

 

#$authorization = "Bearer " + (get-item env:DropBoxAccessToken).Value

$authorization = "Bearer " + 'KEY'

 

$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

3 Replies 3

Greg-DB
Dropbox Staff

Can you elaborate on what you mean when you say the uploaded file is corrupted? For instance, is the file bigger or smaller than expected? You could also try downloading the file and opening it as text to see what the data, if any, actually is.

 

In any case, I just tried this myself, plugging in a test access token and my own path values, and it correctly uploaded the file for me.

Shushu
New member | Level 2

Thanks for your reply. 

 

  I'm downloading .tiff files and the size varies 4.9MB, 9MB, 44MB, 106MB, files less than 4MB they get to the dropbox without issues, once the file is at my download folder, i'm changing the file name (Get-ChildItem -Path C:\User\Downloads -Filter *.tiff | Rename-Item -NewName {$Name+ $_.extension}) and then using the API to sent the file over. 

 

Regards. 

Greg-DB
Dropbox Staff

I just tried again with a .tiff file, about 10 MB, and it still worked correctly for me, so it sounds like there's something in your environment not working as expected.

 

Is there some sort of file size limit or timeout on your network client?

 

How does the size of the corrupted uploaded file compare to the original file? In what way is it corrupted exactly? Have you inspected the contents?

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Shushu New member | Level 2
What do Dropbox user levels mean?