Android Question Receiving pictures from a PC (VB6) server

Carlos Muniz

Member
Licensed User
Longtime User
Hi:

A am trying to receive jpg pictures from a PC server. I couldn't find a good example everywhere. Can anyone help me with a good and (mainly) simple example ? Please,
tell the library used in the example.

Thank you very much.
 

JohnC

Expert
Licensed User
Longtime User
What type of connection would you like to use? (USB, Wifi)
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Library OkHHTPUtils2

DownloadPhotoHTTP:
private Sub DownloadPhotoHTTP()
    
    Try
        Dim J As HttpJob
        Dim URL As String
        Dim F As Boolean,FL As Boolean
        Dim S As Int,FS As Int
        Dim MySQL As String
        Dim Cursor1 As Cursor
        Dim Res As Boolean
        Dim Photo As String
        Dim Logo As String
        
        
        MySQL="select FacilityID,FacilityName,ProviderID,UserID,ProviderPhoto,ProviderName,Address,City,State,Zip,Phone,Logo from tblFacility order by FacilityName"
        
        Cursor1=SQL1.ExecQuery(MySQL)
        
        
        
        For i=0 To Cursor1.RowCount-1
                        
            Cursor1.Position=i
            
            Photo=Cursor1.GetString("ProviderPhoto")
            
            If Photo="" Then
                Continue   
            End If
                        
            F=File.Exists(Main.filedir, Photo)
            S=File.Size(Main.filedir, Photo)
            
            
            If F = False Or s=0 Then
                URL= modFun.URLImage & Photo' Let say http://servername/imahes/photo.jpg
        
                j.Initialize("", Me)
        
                j.Download(URL)
        
                Wait For (j) JobDone(j As HttpJob)
        
                If j.Success Then
            
                    Dim out As OutputStream = File.OpenOutput(Main.FileDir, Photo, False)
                    File.Copy2(j.GetInputStream, out)
                    out.Close '<------ very important
                    Log("Photo " & Photo & " downloaded Ok")
                    Main.TestRet=True
                Else
                
                    modFun.ShowError("HTTP Download error " &  CRLF & "Try again later with better connection and check if photo exists on a provider profile.")
                    Main.TestRet=False
                End If
        
                j.Release
            
            End If
            
        
        Next
        
        i=0
        
        If Main.TestRet=False Then
            'ProgressDialogHide
            'Return
        End If
        
        For i=0 To Cursor1.RowCount-1
                        
            Cursor1.Position=i
            
            Logo=Cursor1.GetString("Logo")
            
            If Logo="" Then
                Continue
            End If
            
                        
            FL=File.Exists(Main.filedir, Logo)
            FS=File.Size(Main.filedir, Logo)
            
        
            If FL = False Or FS=0 Then
                
                URL= modFun.URLImage & Logo
        
                j.Initialize("", Me)
        
                j.Download(URL)
        
                Wait For (j) JobDone(j As HttpJob)
        
                If j.Success Then
            
                    Dim out As OutputStream = File.OpenOutput(Main.FileDir, Logo, False)
                    File.Copy2(j.GetInputStream, out)
                    out.Close '<------ very important
                    Log("Logo " & Logo & " downloaded Ok")
                    Main.TestRet=True
                Else
                
                    modFun.ShowError("HTTP Download error. Try again later with better connection. Also check if the profile has a photo.")
                    Main.TestRet=False
                End If
        
                j.Release
            
            End If
            
        Next
        
        Log("DownloadPhotoHTTP " & Main.TestRet)
        CallSubDelayed(Me,"DownloadPhotoHTTP_Complete")
        
    Catch
        Log("DownloadPhotoHTTP " & LastException)
        modFun.ShowError("DownloadPhotoHTTP " & LastException)
        Main.TestRet=False
    End Try
    
End Sub
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Another possible method...

I don't know what version of windows you have, but it might support being an FTP server (using IIS).

I believe you can find this out by going into "Programs and Features", then selecting "Turn windows features on or off" near the top left corner of the "Programs and Features" window.

Look for a line called "Internet Information Services" and expand it.

If you see "FTP", check it and it will add FTP server functionality to your windows IIS server.

You can then use the FTP functions in B4A to send and receive files to your PC.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Another possible method...

I don't know what version of windows you have, but it might support being an FTP server (using IIS).

I believe you can find this out by going into "Programs and Features", then selecting "Turn windows features on or off" near the top left corner of the "Programs and Features" window.

Look for a line called "Internet Information Services" and expand it.

If you see "FTP", check it and it will add FTP server functionality to your windows IIS server.

You can then use the FTP functions in B4A to send and receive files to your PC.
FTP is not an option if you want to secure your traffic.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
FTP is not an option if you want to secure your traffic.
I only made the suggestion because he is using his own PC as a server, so it appeared to be a personal app, not needing high security.

He could also set the ftp user to be read-only so there is no danger of modifying/uploading anything.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
I only made the suggestion because he is using his own PC as a server, so it appeared to be a personal app, not needing high security.

He could also the ftp user be read-only so there is no danger of modifying/uploading anything.
Ok, but regular http is better.
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
It depends, if you want to get a list of available files in a directory (so you can pick which one you want to download), I don't think that is possible with HTTP without creating a custom web function/service to generate the list.

With FTP, it's a simple function to do that, plus get file sizes, etc.

We don't know a lot about the OP's requirements for their app, so anyone would be just guessing on whats best.

I was simply offering an alternative method to http.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
Not always local
You mean you created a dns or set your servername map to your server IP by editing C:\Windows\System32\drivers\etc\hosts ?
Otherwise I am not sure how another device in the same network able to connect to your server.

Httpjob works with http url like http://{IP Address or domain.com }/subfolder/filename.ext. It is different from how we access a file through typing the file location in windows explorer like \\servername\shareddirectory\filename.ext

Correct me if I am wrong.

Edit: Sorry, I thought you are the OP.
 
Last edited:
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
You mean you created a dns or set your servername map to your server IP by editing C:\Windows\System32\drivers\etc\hosts ?
Otherwise I am not sure how another device in the same network able to connect to your server.

Httpjob works with http url like http://{IP Address or domain.com }/subfolder/filename.ext. It is different from how we access a file through typing the file location in windows explorer like \\servername\shareddirectory\filename.ext

Correct me if I am wrong.

Edit: Sorry, I thought you are the OP.
I mean that I have in my database a url to the server. It might be anywhere on the Internet. I just pull it from the DB by using modFun.URLImage function that does this job.
Have you ever heard about DynDNS?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Upvote 0
Top