Android Question RDC and DecodeBase64

alienhunter

Active Member
Licensed User
Longtime User
Hi
I am using this code in B4J but in B4A it does not work when using RDC
it comes up with : java.io.IOException: Bad Base64 input character decimal 91 in array position 0" error
In the SQL it is decoded and stored as longblob

B4X:
    Dim su As StringUtils
       Dim b() As Byte = su.DecodeBase64(records(6))
       Dim in As InputStream
       in.InitializeFromBytesArray(b, 0, b.Length)
       Dim out As OutputStream
       out=File.OpenOutput(File.DirDefaultExternal, records(5) & ".db",False)
       out.WriteBytes(b, 0, b.Length)
       out.Flush
       out.Close
any clues ?
thanks AH
 

alienhunter

Active Member
Licensed User
Longtime User
Note that you can use blobs directly with RDC. No need to encode or decode the bytes to base64 string.

What is the output of Log(records(6)) ?

Thank you for your time
i used direct blobs before , but i want to give
them the option to use both alternatives , so if the RDC server is down they could use the direct sql
connection and with base64 and php ... just in case .
RDC is still the king here ;)

here is the log of the record(6) [B@dd75fec
out of B4A android

and here is how i encode this in B4J
B4X:
    Dim su As StringUtils
    Dim filex As String
    filex=su.EncodeBase64(Bit.InputStreamToBytes(File.OpenInput("C:\Temp\",featureselctid.Text & ".db"))) 
    uploadblob(filex)


thank you
AH
 
Upvote 0

alienhunter

Active Member
Licensed User
Longtime User
Thanks

this code is calling direct from the sql in b4j and it works , i am a bit confused why it would work here


B4X:
Sub sqldetfeat_QueryComplete (Success As Boolean, Crsr As ResultSet)
  
If Success=True  Then
  
Do While Crsr.NextRow
  
ncjobsjobloaded.Text=Crsr.GetString("jobnr") &"/"& Crsr.GetString("partd")&"/"& Crsr.GetString("setup")&"/"& Crsr.GetString("machi")
featureselctid.Text=Crsr.GetString("unid")

            Dim su As StringUtils
            Dim b() As Byte = su.DecodeBase64(Crsr.GetString2(6))
            Dim in As InputStream
            in.InitializeFromBytesArray(b, 0, b.Length)
            Dim out As OutputStream
            out=File.OpenOutput("C:\temp", featureselctid.Text & ".db",False)
            out.WriteBytes(b, 0, b.Length)
            out.Flush
            out.Close
buildselectiontree
   
Loop
Crsr.Close  

Else  
      
Log(LastException)      
      
      
End If
  
End Sub
 
Upvote 0

Jhonn

Member
Checks first char of your data, some server and codes add a extra hidden character at begin of data, remove first character from the string, try records(6).SubString(1)

B4X:
    Dim su As StringUtils
       Dim b() As Byte = su.DecodeBase64(records(6).SubString(1))
       Dim in As InputStream
       in.InitializeFromBytesArray(b, 0, b.Length)
       Dim out As OutputStream
       out=File.OpenOutput(File.DirDefaultExternal, records(5) & ".db",False)
       out.WriteBytes(b, 0, b.Length)
       out.Flush
       out.Close
 
Last edited:
Upvote 0
Top