Hi everyone!
Hope you can help me out with this one:
We have a VOIP provider which stores calls for a maximum of 30 days, hence, we download them and upload the .wav files to Dropbox so we can have them forever stored.
Until a few days ago, we used the following script to automate the process, HOWEVER, now the calls are downloaded, folders are created on Dropbox, but the files are not uploaded. Did you guys change something in the API or is there something missing now in the code?
function Upload-FileToDropbox {
Param(
[Parameter(Mandatory=$true)]
[string]$SourceFilePath,
[Parameter(Mandatory=$true)]
[string]$TargetFilePath,
[Parameter(Mandatory=$true)]
[string]$DropBoxAccessToken
)
$arg = '{ "path": "' + $TargetFilePath + '", "mode": "add", "autorename": true, "mute": false }'
$authorization = "Bearer $DropBoxAccessToken"
$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')
Write-Verbose "Uploading file: $SourceFilePath"
try {
Invoke-RestMethod -Uri https://content.dropboxapi.com/2/files/upload -Method Post -InFile $SourceFilePath -Headers $headers
}
catch {
Write-Error $_.Message
}
}
function Create-FolderInDropbox {
Param(
[Parameter(Mandatory=$true)]
[string]$FolderPath,
[Parameter(Mandatory=$true)]
[string]$DropBoxAccessToken
)
$JSONBody = @{ "path"=$FolderPath; "autorename"=$false} | ConvertTo-Json
$authorization = "Bearer $DropBoxAccessToken"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $authorization)
$headers.Add("Content-Type", 'application/json')
Write-Verbose "Creating folder: $FolderPath"
Invoke-RestMethod -Uri https://api.dropboxapi.com/2/files/create_folder_v2 -Method Post -Headers $headers -Body $JSONBody
Write-Error $_.Message
}
function Rename-WaveFile {
Param(
[Parameter(Mandatory=$true)]
[System.IO.FileSystemInfo]$File
)
$XMLFile = [xml](Get-Content ($File.Fullname).Replace(".wav", ".xml"))
$StartDate = [DateTime]::Parse($XMLFile.Recording.start).ToString("yyyyMMdd-hh.mm.ss")
$AgentID = $XMLFile.Recording.userid
$FileID = $File.BaseName
$NewFileName = "$FileID-$StartDate-$AgentID.wav"
Write-Verbose "Renaming $($File.Name) to $NewFileName"
$NewFile = Rename-Item -Path $File.Fullname -NewName $NewFileName -Confirm:$false -Force -PassThru
return $NewFile
}
#Confidential credentials
$DropboxAccessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$User = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$Password ="xxxxxxxxxx"
$ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
#Declare variables
$DownloaderExe = "C:\FuzeDownloader\RecordingsDownloader\RecordingsDownloader.exe"
#$Today = (Get-Date).ToString("yyyy-MM-dd")
$Today = "2022-04-21"
$DropboxFolderPath = "/FuzeRecordings/$Today"
$WavPath = "C:\FuzeDownloader\RecordingsDownloader\RecordingsDownloaderOutput\"
$numbers = 0
#Download Wav files
Push-Location $ScriptPath
$DownloaderProc = Start-Process -FilePath $DownloaderExe -ArgumentList "-d$Today -u$User -p$Password" -PassThru -NoNewWindow
while (Get-Process -Id $DownloaderProc.Id) {
if ($(Get-Date) -gt $DownloaderProc.StartTime.AddHours(8)) {
Write-Error -Message "Script has been running for over 8 hours. Something's wrong."
exit 666
}
Start-Sleep -Seconds 5
}
#Create Folder for today's calls
Create-FolderInDropbox -FolderPath $DropboxFolderPath -DropBoxAccessToken $DropboxAccessToken
$WavFiles = Get-ChildItem -Path $WavPath -Include "*.wav" -Recurse
foreach ($Wav in $WavFiles) {
#Rename Wave files to show date, time and user name
$RenamedFile = Rename-WaveFile $Wav
#Once renamed, upload it to Dropbox
Upload-FileToDropbox -SourceFilePath $RenamedFile.FullName -TargetFilePath "$DropboxFolderPath/$($RenamedFile.Name)" -DropBoxAccessToken $DropboxAccessToken
$numbers++
------------------------------------------------------------------------
I've replaced access token and credentials with "xxxxxxx"
No error message is thrown on the output.
Thanks in advance for the help!