B4J Question bin.base64

BeneBarros

Active Member
Licensed User
Longtime User
I am developing a system for a company and by default all images that are written in SQL are in the format "jpg", as already use some other systems.

as the server is remote I am sending data via XML.

Today I make a shell in a VB program using oDomDocument and performance is good.

Is there a way to convert the jpg file to "bin.base64" directly from B4J eliminating the shell in VB, while maintaining compatibility with other sitemas?

All other data, have no problem, as few in image files need help.
 

BeneBarros

Active Member
Licensed User
Longtime User
Of course. You can use StringUtils to encode or decode base 64 strings.
Good morning Erel .
I tried to use the StringUtils to encode bin.base64.
happens that when I load the file to the stream and use StringUtils to convert the result is different from the generated DomDocument file.

using .png files in the result is the same, but in jpg files is not.

I'll make an example of how I'm doing and post here.

thank you for now ..
 
Upvote 0

BeneBarros

Active Member
Licensed User
Longtime User
I believe that now works.
changed the codes as follows:
B4X:
Sub Get_jpgbase64(im as Image) as string
    Dim myPath As String =  GetCanonicalPath(File.DirTemp)
    Dim pngFile As String = "tmpFoto.png"
    Dim jpgFile As String = "tmpFoto.jpg"
    Dim result As String
    If File.Exists(myPath, pngFile) Then
        File.Delete(myPath, pngFile)
    End If
    If File.Exists(myPath, jpgFile) Then
        File.Delete(myPath, jpgFile)
    End If
    Dim Out As OutputStream = File.OpenOutput(myPath, pngFile, False)
    im.WriteToStream(Out)
    Out.Close
    Dim pngTojpg As pngTojpg
    pngTojpg.convert(myPath & "\" & pngFile, myPath & "\" & jpgFile)
    Dim In As InputStream = File.OpenInput(myPath, jpgFile)
    Dim bts As Int = In.BytesAvailable
    Dim Buffer(bts) As Byte
    In.ReadBytes(Buffer, 0, bts)
    Dim su As StringUtils
    Dim eElement_Value As String = su.EncodeBase64(buffer)
    'Log(eElement_Value.SubString(eElement_Value.Length-50))
    In.Close
   Return eElement_Value
End Sub
the only difference that remains is that oDomDocument adds at the end of the string element "AA ==".
I will ignore and test.
 
Upvote 0

BeneBarros

Active Member
Licensed User
Longtime User
I believe that now works.
changed the codes as follows:
B4X:
Sub Get_jpgbase64(im as Image) as string
    Dim myPath As String =  GetCanonicalPath(File.DirTemp)
    Dim pngFile As String = "tmpFoto.png"
    Dim jpgFile As String = "tmpFoto.jpg"
    Dim result As String
    If File.Exists(myPath, pngFile) Then
        File.Delete(myPath, pngFile)
    End If
    If File.Exists(myPath, jpgFile) Then
        File.Delete(myPath, jpgFile)
    End If
    Dim Out As OutputStream = File.OpenOutput(myPath, pngFile, False)
    im.WriteToStream(Out)
    Out.Close
    Dim pngTojpg As pngTojpg
    pngTojpg.convert(myPath & "\" & pngFile, myPath & "\" & jpgFile)
    Dim In As InputStream = File.OpenInput(myPath, jpgFile)
    Dim bts As Int = In.BytesAvailable
    Dim Buffer(bts) As Byte
    In.ReadBytes(Buffer, 0, bts)
    Dim su As StringUtils
    Dim eElement_Value As String = su.EncodeBase64(buffer)
    'Log(eElement_Value.SubString(eElement_Value.Length-50))
    In.Close
   Return eElement_Value
End Sub
the only difference that remains is that oDomDocument adds at the end of the string element "AA ==".
I will ignore and test.

RESOLVED
Build the xml element and bin.base64 in B4J
ASP Server uses oDomDocument and processes without errors.
thank you ...
good afternoon
 
Upvote 0
Top