How to send a Captured Photo to SQL Server

ytlit

New Member
Licensed User
Longtime User
Hi, I am trying to send a camera captured image to be saved as binary in MS SQL Server.
B4X:
' FOR CONVERTING IMAGE TO STRING SEND OVER THROUGH WEB SERVICE
      Dim str64Pic As String   
      If strPhotoSnapName <> "" Then
         Dim in As InputStream
         Dim out As OutputStream

         in = File.OpenInput(File.DirRootExternal, strPhotoSnapName)
         out.InitializeToBytesArray(0)
         File.Copy2(in, out) 
         Dim data() As Byte
         data = out.ToBytesArray

         Dim b64 As Base64   
         b64.BreakLines = True
         b64.UrlSafe = True
         b64.LineLength = 75
         
         str64Pic = b64.EncodeBtoS(data,0,data.Length)
         str64Pic = strStringUtils.EncodeUrl(str64Pic, "UTF8")
         
      End If

Then sending it to the server using HTTPRequest

B4X:
Dim request As HttpRequest
request.InitializeGet("http://8.8.8........./default.aspx?image=" & str64Pic)   
request.Timeout = 10000 'set timeout to 10 seconds   
If HttpClientAccess.Execute(request, 5) = False Then Return 
ProgressDialogShow("Processing...")

The above codes works for very small images because of limitation on the generated URL length, unfortunately, larger images cannot work and hit error. Is there other alternatives to this? Please advice, thanks.
 

ytlit

New Member
Licensed User
Longtime User
Thanks.

Do you have a sample please.
I am worried even if we use HTTPUtils2, it will still generate a very long URL when we send it back using HttpClientAccess.
 
Upvote 0
Top