Base64 string longest length

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
atostaine
Posts: 475
Joined: Wed Jan 20, 2016 7:38 am

Base64 string longest length

Post by atostaine » Tue Oct 01, 2019 4:07 am

I return an image from VL-WEB to a Server routine in a list with each entry being a 65535 chunks. The picture is 1-4 megapixels. I want to concatenate it all into one field so I can do something like this:

#BinaryData.FromBase64String String(#image64) ErrorInfo(#errorInfo)

Image64 is #prim_alph, can it hold all of those characters? I'm getting invalid base64 string in my ErrorInfo result.

Thanks, Art
Art Tostaine

User avatar
lawingo
Posts: 53
Joined: Fri Dec 04, 2015 6:41 am

Re: Base64 string longest length

Post by lawingo » Tue Oct 01, 2019 4:44 am

Hey Art,

I'm doing something similar in one of my applications. Keep in mind I am using the Camera Widget. I created a CLOB field to hold the base64 string(s).

Reusable Part to Capture the Image:

Code: Select all

Evtroutine Handling(#CameraControl.Completed) Base64data(#base64) File(#file)
Define_Com Class(#wbepSM01.InsertWBEP) Name(#WBEPInsert)

#Image1.FileName := #base64
#W_LENGTH := #base64.CurSize

Clr_List Named(#L_IMG64)
#W_START := 1
#W_END := 65000
Dountil Cond(#W_END = #W_LENGTH)

#W_BLOBH := #base64.Substring( #W_START #W_END )
Add_Entry To_List(#L_IMG64)

#W_START := #W_START + 65000
#W_END := #W_END + 65000

If Cond(#W_END > #W_LENGTH)
#W_END := #W_LENGTH
Add_Entry To_List(#L_IMG64)
Leave
Endif

Enduntil

Endroutine
Server Routine to create CLOB Field:

Code: Select all

Define Field(#W_BLOBH) Type(*STRING) Length(65000)
Def_List Name(#L_IMG64) Fields(#W_BLOBH) Type(*WORKING) Entrys(*MAX)

Use Builtin(STM_FILE_OPEN) With_Args('D:\temp\WBEP.txt' 'Write LineTerminator=NONE') To_Get(#STSTGRJP)

Selectlist Named(#L_IMG64)
Use Builtin(STM_FILE_WRITE) With_Args(#STSTGRJP #W_BLOBH)
Endselect
Use Builtin(STM_FILE_CLOSE) With_Args(#STSTGRJP)

#WBEPIMG := 'D:\temp\WBEP.txt'

Use Builtin(OV_FILE_SERVICE) With_Args('REMOVE_FILE' 'D:\temp\WBEP.txt')

Fetch the Image from the Clob (Rebuild the List) (Server Module )

Code: Select all

Use Builtin(STM_FILE_OPEN) With_Args(#WBEPIMG.FileName 'Read') To_Get(#STSTGRJP)
Dountil Cond((#FW_RETCD <> 'OK') And (#FW_RETCD <> 'OV'))
Use Builtin(STM_FILE_READ) With_Args(#STSTGRJP) To_Get(#W_BLOBH #FW_RETCD)
Add_Entry To_List(#L_VIMG64)
Enduntil
Use Builtin(STM_FILE_CLOSE) With_Args(#STSTGRJP)
(Reusable Part) View the Image

Code: Select all

Selectlist Named(#MainList)
#Base64 := *null

Selectlist Named(#L_VIMG64) Where(#DVDVID = #WBEPID)
#Base64 := #Base64 + #W_BLOBH
Endselect

If Cond(#Base64.IsNull = False)
#ExitPhoto.CurrentItem.Image <= #SYS_APPLN.CreateBitmap( #Base64 )
Endif

Endselect
I hope this helps!

Best
Chad
Sherrill Furniture Companies

atostaine
Posts: 475
Joined: Wed Jan 20, 2016 7:38 am

Re: Base64 string longest length

Post by atostaine » Tue Oct 01, 2019 4:56 am

Yes that's the way I'm doing it now. We also use the camera widget. When I first went through the development on this I wrote another server routine for testing that used FromBase64String.

LansaMobile is crashing for us on Windows 10 and we are trying to rewrite anything we can do to stop the crash while we wait for LANSA support.
Art Tostaine

Post Reply