Android Question Downloading large images showing Progress bar

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi Guys,

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.

Is there any better way out.

Juzer
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
I think that you are mistaken. FTP does not know, or care, what sort of data is contained within a file.

Is this link the one that you are referring to?
 
Last edited:
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
No Brian, I am not referring to that link.
I have to download images only upto 10MB size and need to show progress bar accurately.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
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
 
Last edited:
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
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.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
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.

Example:


Edit: ok, not the right Script in this Context as it does not list the Filesize but the ImageDimensions.
But from principle it should be a start

PHP:
<?php
header("content-type: text/plain");
$result = array();

foreach (glob('/www/htdocs/w00d7468/b4a.snapshots/*.png') as $filename) {
    $thisfile = array();

    $path_parts = pathinfo($filename);

    $thisfile["filename"] = $path_parts['basename'];
    $thisfile["ext"] = $path_parts['extension'];
    #echo $filename." - Größe: " . filesize($filename) . "\n";
    $size = getimagesize( $filename);
  $thisfile["width"] = $size[0];
  $thisfile["height"] = $size[1];
  $thisfile["filesize"] = filesize($filename); # FILESIZE is new here....
  # echo "Bildbreite: " . $size[0];
  # echo "Bildhöhe: " . $size[1];
  $result[] = $thisfile;
}
echo json_encode($result);
?>
 
Last edited:
Upvote 0
Top