Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

Shushu's avatar
Shushu
New member | Level 2
5 years ago

Corrupted Files using API in PowerShell

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

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    5 years ago

    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's avatar
    Shushu
    New member | Level 2
    5 years ago

    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's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    5 years ago

    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?

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API
Make connections with other developers

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!