Android Question Best Practice for saving Photos in Android

joaquinortiz

Active Member
Licensed User
Longtime User
I start thinking on a new app to develop that has to take photo, but I realize which method is better to save photos that I'll take with the celular camera. Save it on the cellphone or save it through a server via WebService?

Can anyone share your experience?

Thanks in advance!.
 

Alex_197

Well-Known Member
Licensed User
Longtime User
I start thinking on a new app to develop that has to take photo, but I realize which method is better to save photos that I'll take with the celular camera. Save it on the cellphone or save it through a server via WebService?

Can anyone share your experience?

Thanks in advance!.
Save it on a cellphone as files, store their name in the database.
Then run a query to pull these names from a database table and then send these files either via FTP or a web service with POST request back to your server
 
Upvote 0

joaquinortiz

Active Member
Licensed User
Longtime User
Save it on a cellphone as files, store their name in the database.
Then run a query to pull these names from a database table and then send these files either via FTP or a web service with POST request back to your server

Thanks Alex, for your help!...So it's the same thing. I would do the same processs in Windows Mobile (Vb.net).
 
Upvote 0

joaquinortiz

Active Member
Licensed User
Longtime User
VB.NET, Windows Mobile, SQL CE 3.5... what a good time:)

Yesssss!!!!, Golden Season!!!!......where windows mobile and .net give us an easy way to develop rapidly mobile apps.....hahahahahha!!!!.

Which could be better way? sending via FTP or WebServices the photos?.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
Yesssss!!!!, Golden Season!!!!......where windows mobile and .net give us an easy way to develop rapidly mobile apps.....hahahahahha!!!!.

Which could be better way? sending via FTP or WebServices the photos?.
It depends on security settings.

For Web service you can use https. And you don't need to set up FTP on your IIS.

I'm using web service because SFTP is not an option B4A doesn't support SFTP.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
It depends on security settings.

For Web service you can use https. And you don't need to set up FTP on your IIS.

I'm using web service because SFTP is not an option B4A doesn't support SFTP.
Second reason why I'm using web service vs FTP.

Web service allows to you to use ResumableSub - it's very convinces if you need to send / receive data one after another.
But FTP is another process and you need to make sure that one process has finished before starting FTP.
It was a problem for me.

Please see my code

Download Photo:
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
        
                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
Top