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
4 years agoNew member | Level 2
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-DBDropbox 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.
- ShushuNew 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-DBDropbox 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?
About Discuss Dropbox Developer & API
Make connections with other developers
795 PostsLatest Activity: 4 days agoIf 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 or Facebook.
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!