public Sub UploadMedia
Try
Dim MySQL As String
Dim Cursor1 As ResultSet
Dim IsFTPOk As Boolean
MySQL="select ID, FileName from tblNotesMediaFiles "
MySQL= MySQL & "where PlacementLocalID=? And PlacementID=? And JobDate=? And Shift=? And ifnull(FTPDate,'1/1/1900')='1/1/1900'"
FileName=""
Dim files As List,Records As List
Dim job As HttpJob
files.Initialize
Records.Initialize
Cursor1=Main.SQL1.ExecQuery2(MySQL,Array As String(Main.SelectedPlacementLocalID, Main.SelectedPlacementID, Main.SelectedDOS,Main.SelectedShift))
Do While Cursor1.NextRow
FileName=Cursor1.GetString("FileName")
If FileName<>"" Then
If File.Exists(Main.FileDir,FileName) Then
RecordID=Cursor1.GetInt("ID")
Records.Add(RecordID)
Dim fd As MultipartFileData
fd.Initialize
If FileName.Contains("jpg") Then
fd.KeyName = "imagejpg"
fd.ContentType = "image/jpg"
else if FileName.Contains("png") Then
fd.KeyName = "imagepng"
fd.ContentType = "image/png"
Else
fd.KeyName = "audiowav"
fd.ContentType = "audio/wav"
End If
fd.FileName = FileName
fd.Dir = Main.FileDir
files.Add(fd)
End If
End If
Loop
Cursor1.Close
If files.Size>0 Then
For j=0 To files.Size-1
Dim CurrentFile As List,CurrentRecord As List
CurrentFile.Initialize
CurrentRecord.Initialize
CurrentFile.Add(files.Get(j))
CurrentRecord.Add(Records.Get(j))
Dim job As HttpJob
job.Initialize("Upload",Me)
job.PostMultipart(Main.modFun.URL ,CreateMap("action":"upload", "Ticket":Main.Ticket,"RegKey":Main.RegKey,"WhatToDo":"receivefiles","IsIOS":"Yes"),CurrentFile)
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
Dim response As String
response=job.GetString
Log("File " & j & " was uploaded successfully " & job.GetString )
IsFTPOk=Main.modFun.ApplyUploadConfirmation(response,CurrentFile,CurrentRecord)
If IsFTPOk=False Then
Main.modFun.ShowError("clsRefreshJobs_File upload has failed " & response & CRLF & "Try again later with better connection")
End If
Else
Main.modFun.ShowError("clsRefreshJobs_HTTP Upload error " & LastException.Message & CRLF & "Try again later with better connection")
IsFTPOk=False
End If
job.Release
Next
End If
If IsFTPOk=False Then
Main.TestRet=False
End If
CallSubDelayed(Me,"UploadMedia_Complete")
Catch
HUD.ProgressDialogHide
Log("UploadMedia " & LastException.description)
Main.modFun.ShowError("clsRefreshJobs_UploadMedia " & LastException.description)
End Try
End Sub