Hi All...
I am making a file upload function in my program which is to upload 100s of text files back to my webserver hosting a PHP script which receives the files and stores them locally.
I am able to upload the files successfully. The challenge and problem I am facing is that the number of files which needs to get uploaded keeps increasing as the file generation is continuous and the upload function is not able to keep up with the speed of file generation. Also the functions starts uploading files which has been already uploaded but waiting for deletion confirmation to be received.
I am using HttpUtils2 for file uploading. Below code does the file upload for me. I call this in a timer which runs every 1 second.
Can anyone please guide and help me in making the function better which will ensure the files already uploaded does not get uploaded again and if possible upload multiple files in one go. Thanks in advance..
Regards,
Sangee
I am making a file upload function in my program which is to upload 100s of text files back to my webserver hosting a PHP script which receives the files and stores them locally.
I am able to upload the files successfully. The challenge and problem I am facing is that the number of files which needs to get uploaded keeps increasing as the file generation is continuous and the upload function is not able to keep up with the speed of file generation. Also the functions starts uploading files which has been already uploaded but waiting for deletion confirmation to be received.
I am using HttpUtils2 for file uploading. Below code does the file upload for me. I call this in a timer which runs every 1 second.
B4X:
Sub UploadTimer_Tick
Dim fileList As List
Dim n As Int
Dim file1 As String
fileList = File.ListFiles(File.DirRootExternal & "/Download/ubtxt/Files/")
fileList.Sort(True)
lblfilesinque.Text = fileList.Size
If fileList.Size > 0 Then
' Loop through the list. upload the first file in the queue and exit loop
For n = 0 To fileList.Size-1
file1 = fileList.Get (n)
FileJob = file1
Dim job2 As HttpJob
job2.Initialize(FileJob,Me)
job2.PostFile("http://www.xxxxxxxx.com/uploadimg.php?filename=" & fileList.Get(0),File.DirRootExternal & "/download/ubtxt/Files/", file1)
Exit ' Exit for loop after processing the first file
Next
End If
End Sub
Sub JobDone (Job As HttpJob)
Dim Filename As String
If Job.Success = True Then
Select Job.JobName
Case "Job1"
'Get and set the device status
DevStatus(Job.GetString)
Case FileJob
Filename = Job.GetString
Filename = Filename.Trim
File.Delete (File.DirRootExternal & "/Download/ubtxt/Files/",Filename)
ToastMessageShow("Upload Ok: " & Filename ,False)
End Select
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Can anyone please guide and help me in making the function better which will ensure the files already uploaded does not get uploaded again and if possible upload multiple files in one go. Thanks in advance..
Regards,
Sangee