When we download any image using FTP (as i read somewhere) we don't get TotalDownloaded value in DownloadProgress event.
Is it now possible to get this value ?
I am fist checking file size on server and then downloading, Which takes double time.
Earlier i would add file size in the name when uploading, which i don't want to use.
Okay. Have you actually tried an FTP download? I cannot see where you would have a problem. You will need to do an FTP.List first to get the file size, but this does not take "double time" as you mention in your first post.
Here is a code sample (not tested) ...
B4X:
Type fileInfo(filename As String, filesize As Int, timestamp As Long)
Private Sub makeFilelist
FTP.List(hostPath) ' Get filelist from host
Wait For FTP_ListCompleted (ServerPath As String, Success As Boolean, _
Folders() As FTPEntry, Files() As FTPEntry)
If Success Then
For Each e As FTPEntry In Files
Dim f As fileInfo
f.Initialize
f.filename = e.Name
f.filesize = e.Size
f.timestamp = e.Timestamp
. . .
Next
Else
Log(LastException.Message
End If
End Sub
I am using below working code to get the size of the particular file on server.
B4X:
'Called
Wait For(CallSub2(Me,"PF_FileSize",sImgTNAddress)) Complete (Result As String)
Sub PF_FileSize(sFileName As String) As ResumableSub
Dim j As HttpJob
Dim sPath As String
Dim result As String=""
sPath="http://xyz.com/Folder/ImageFiles/" & sFileName
iProfileImgSize=0
j.Initialize("", Me)
j.download(sPath)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim length As List = j.Response.GetHeaders.GetDefault("content-length", Null)
If length.IsInitialized Then
result=length.Get(0)
iProfileImgSize=result
Return result
End If
End If
End Sub
This is working but slow.
I show the progressbar only after getting the size which confuses the user as it takes time to get the size.
I - personally - would place a php-script on the server which does return the filesizes of all files in this folder. In b4a i would only need to fetch the list to get all (file)sizes i need.