base64 data to pdf
hi there , when i convert a pdf to base64 data, and then restore the data to pdf,i find that ,i must read the same as length of base64 data every time convert ,or i can't get the right pdf. the code is:
s pdf= ##class(%FileBinaryStream).%New()
s pdf.Filename = $g(path)
s len=24*30*2
s byteList = pdf.Read(len)
while(byteList'=""){
s baseStr = ##class(%SYSTEM.Encryption).Base64Encode(byteList)
length of baseStr is 1970,
if len=24*30 length of baseStr is 984,
when i covert the base64 data to pdf, the code is:
s pdf= ##class(%FileBinaryStream).%New()
s pdf.Filename = $g(path)
while ('sgc.AtEnd){
s baseStr = sgc.Read(len1)
s byteList = ##class(%SYSTEM.Encryption).Base64Decode(baseStr)
d img.Write(byteList)
when len is 24*30*2, len1 is 1970,when len is 24*30,len1 is 984, and i can get the right pdf,if the base64 data comes from others, how can i know the num of len1?
Comments
Please note that, by default, Base64Encode() Insert CR/LF after every 76 characters.
Did you take that into account?
yes, i konw it, if not Insert CR/LF after every 76 characters,when len is 24*30*2, len1 is 1920,when len is 24*30,len1 is 960, and i can get the right pdf,if the base64 data comes from others, how can i know the num of len1?
i got it,the code must like this "s baseStr = ##class(%SYSTEM.Encryption).Base64Encode(byteList,1)",len must be 24*n,and len1 must be 8*n