Base64String longer than 65535
Posted: Wed Nov 11, 2020 9:35 am
Hi guys
Any idea how to handle a Base64String longer than 65535? We need to receive PDF files in a JSON restful call and they will arrive encoded as Base64String, but most likely most of them will be much longer than 64Kb. How can we handle that?
I create this simple example (a form, just for test) but my limit as you can see in this example, is the *STRING.
Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientwidth(904) Clientheight(340) Componentversion(2) Left(524) Top(226)
Define Field(#PDFSTRING) Type(*STRING) Length(65535)
Define_Com Class(#XPRIM_Binary) Name(#File)
Define_Com Class(#STD_QSEL.Visual) Name(#STD_QSEL) Componentversion(1) Displayposition(4) Height(21) Left(56) Parent(#COM_OWNER) Tabposition(4) Top(24) Usepicklist(False) Width(600) Caption('PDF File with path') Labeltype(Caption)
Define_Com Class(#PRIM_LABL) Name(#Label1) Caption('Here the PDF as Base64String') Displayposition(2) Ellipses(Word) Height(129) Left(56) Parent(#COM_OWNER) Tabposition(1) Tabstop(False) Top(64) Verticalalignment(Center) Width(396) Wrapstyle(Continuous)
Define_Com Class(#STD_STRNG.Visual) Name(#STD_STRNG) Componentversion(1) Displayposition(3) Left(48) Parent(#COM_OWNER) Tabposition(2) Top(250) Width(769)
Define_Com Class(#PRIM_PHBN) Name(#ButtonStringToBin) Caption('Convert String a FILE') Displayposition(1) Left(640) Parent(#COM_OWNER) Tabposition(3) Top(64) Width(161) Height(57)
Define_Com Class(#PRIM_PHBN) Name(#ButtonFileToString64) Displayposition(5) Left(688) Parent(#COM_OWNER) Tabposition(5) Top(16) Caption('Lee Archivo y Pasa a String') Width(169)
Evtroutine Handling(#com_owner.CreateInstance)
* You can change this to whatever PDF you want to use or when running the form
#STD_QSEL := 'c:\temp\PDF32KB.pdf'
Endroutine
Evtroutine Handling(#ButtonFileToString64.Click)
#File.FromFile Path(#STD_QSEL)
* Move the file to an string 64
#PDFString := #File.AsBase64String
* Display it in the form
#Label1.Caption := #PDFSTRING
Endroutine
Evtroutine Handling(#ButtonStringToBin.Click)
* Pass the string base 64 to file
#File.FromBase64String String(#PDFSTRING)
* Just shows the location of the file... notice that it wont have the correct extension (PDF), you need to rename or copy it to use it.
#STD_STRNG := #File.AsFile
Endroutine
End_Com
Any idea how to handle a Base64String longer than 65535? We need to receive PDF files in a JSON restful call and they will arrive encoded as Base64String, but most likely most of them will be much longer than 64Kb. How can we handle that?
I create this simple example (a form, just for test) but my limit as you can see in this example, is the *STRING.
Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_FORM) Clientwidth(904) Clientheight(340) Componentversion(2) Left(524) Top(226)
Define Field(#PDFSTRING) Type(*STRING) Length(65535)
Define_Com Class(#XPRIM_Binary) Name(#File)
Define_Com Class(#STD_QSEL.Visual) Name(#STD_QSEL) Componentversion(1) Displayposition(4) Height(21) Left(56) Parent(#COM_OWNER) Tabposition(4) Top(24) Usepicklist(False) Width(600) Caption('PDF File with path') Labeltype(Caption)
Define_Com Class(#PRIM_LABL) Name(#Label1) Caption('Here the PDF as Base64String') Displayposition(2) Ellipses(Word) Height(129) Left(56) Parent(#COM_OWNER) Tabposition(1) Tabstop(False) Top(64) Verticalalignment(Center) Width(396) Wrapstyle(Continuous)
Define_Com Class(#STD_STRNG.Visual) Name(#STD_STRNG) Componentversion(1) Displayposition(3) Left(48) Parent(#COM_OWNER) Tabposition(2) Top(250) Width(769)
Define_Com Class(#PRIM_PHBN) Name(#ButtonStringToBin) Caption('Convert String a FILE') Displayposition(1) Left(640) Parent(#COM_OWNER) Tabposition(3) Top(64) Width(161) Height(57)
Define_Com Class(#PRIM_PHBN) Name(#ButtonFileToString64) Displayposition(5) Left(688) Parent(#COM_OWNER) Tabposition(5) Top(16) Caption('Lee Archivo y Pasa a String') Width(169)
Evtroutine Handling(#com_owner.CreateInstance)
* You can change this to whatever PDF you want to use or when running the form
#STD_QSEL := 'c:\temp\PDF32KB.pdf'
Endroutine
Evtroutine Handling(#ButtonFileToString64.Click)
#File.FromFile Path(#STD_QSEL)
* Move the file to an string 64
#PDFString := #File.AsBase64String
* Display it in the form
#Label1.Caption := #PDFSTRING
Endroutine
Evtroutine Handling(#ButtonStringToBin.Click)
* Pass the string base 64 to file
#File.FromBase64String String(#PDFSTRING)
* Just shows the location of the file... notice that it wont have the correct extension (PDF), you need to rename or copy it to use it.
#STD_STRNG := #File.AsFile
Endroutine
End_Com