We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.

Forum Discussion

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

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox 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's avatar
      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's avatar
        Greg-DB
        Icon for Dropbox Staff rankDropbox 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?