Android Question FTP.Upload never fires UploadCompleted with big files (>2MB)

Kwame Twum

Active Member
Licensed User
Longtime User
Hi all, I'm working on an app that uploads (with FTP) a file selected by the user and reports the progress via a progress bar... when UploadCompleted fires, the progress bar disappears.

My app is able to upload files less than 2MB very well (both UploadCompleted and UploadProgress subs fire accordingly). But when the file size is a little bigger the UploadProgress reports the progress alright but then it never gets to the UploadCompleted sub. The progress bar reaches 100% and still stays visible.

When I check the FTP server, I realise the file gets uploaded fully with correct filename, filesize,etc.

What can I be doing wrong? :(
 

Kwame Twum

Active Member
Licensed User
Longtime User
Yes Erel, actually I have a couple of log statements in the UploadCompleted sub... It reports the success value of an upload. When the file size is bigger, the log never shows.
The unfiltered logs are quite confusing (scrolling too fast). However, two lines seem to repeat consistently.
B4X:
Cursor finalized without prior close()
and 
sqlite returned: error code = 17, msg = statement aborts at 43: [UPDATE Master SET RefDateModified=? WHERE FullPath=?] database schema has changed
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've tried the following code with a 9mb file and it works correctly:
B4X:
Sub Process_Globals
   Dim FTP As FTP
End Sub

Sub Globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     FTP.Initialize("ftp", ...)
     FTP.UploadFile(File.DirRootExternal, ...)
   End If
End Sub
Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
   Activity.Title = TotalUploaded
End Sub

Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
   Log("Completed: " & Success)
End Sub

Make sure that the activity is not paused during the upload.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Just a follow on from this. (didn't think it deemed it's own thread) if uploading large files like this is it worth using a foreground service?
 
Upvote 0

Kwame Twum

Active Member
Licensed User
Longtime User
thanks a lot guys... I'll give it a try when I get home.
 
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
Hi! I'm getting now the same problem, it never fires FTP_UploadCompleted

before some modifications (not to ftp code section) it works. what could be???

this is my code:

B4X:
  If okexp = "X" Then 'export solo se ci sono record
       File.WriteList(sdRoot,Nfile,List1)
       List1.Clear   
       TxtLog.Text = "Creato File "&Nfile&Chr(10)&TxtLog.Text
       If FTPMode="F" Then    'connessione FTP
         TxtLog.Text = "Connessione FTP "& FTPHost &"(" &FTPPort &") in Corso..." &Chr(10)&TxtLog.Text
         TxtLog.Text = "Invio File "& Nfile &Chr(10)&TxtLog.Text
         FTP.UploadFile(sdRoot, Nfile, True, Nfile)
       '   Do While okexp <> "S" AND okexp <> "N"
       '     DoEvents
       '   Loop
       End If
       ProgressBar1.Progress = 100
       LblStatus.Text = ProgressBar1.Progress &"%"
       Msgbox2("Esportazione completata!",Main.nomeprog,"","Ok","",LoadBitmap (File.DirAssets, "warning_small.png"))
     Else
       Msgbox2("Non ci Sono Dati da Esportare!",Main.nomeprog,"","Ok","",LoadBitmap (File.DirAssets, "warning_small.png"))
     End If

B4X:
Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
  Dim s As String
  s = "Uploaded " & Round(TotalUploaded) & "B"
  If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
  Log(s)
   LblProgress.Text = s
End Sub

Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
  Log(ServerPath & ", Success=" & Success)
   ProgressBar1.Progress = ProgressBar1.Progress + 25
   LblStatus.Text = ProgressBar1.Progress &"%"
   Msgbox(Success,"esito")
   If Success = True Then
     TxtLog.Text = "File "&Nfile&" Inviato con Successo!" &Chr(10)&TxtLog.Text
     Dim Answ As Int
     Answ=Msgbox2("Elimino dal Tablet il File Inviato?",Main.nomeprog,"Si","","No",LoadBitmap (File.DirAssets, "warning_small.png"))
     If Answ=DialogResponse.POSITIVE Then
       File.Delete(sdRoot,Nfile.trim)
     End If
     ContrassegnaRecord
     okexp="S"
   Else
     ProgressBar1.Progress = 100
     Msgbox2("Errore nell'Invio File "&Nfile&"!",Main.nomeprog,"","Ok","",LoadBitmap (File.DirAssets, "warning_small.png"))
     File.Delete(sdRoot,Nfile.Trim) ' cancello il file dal tablet
     ' chiudiamo la connessione
     FTP.CloseNow
     Timer1.Initialize("Timer1",4000)
     Timer1.Enabled=True
     okexp="N"
   End If
End Sub
 
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
no, i can't, before some modifications to other parts of the app it works....and the file is only 200kb!

why?
 
Upvote 0
Top