Page 1 of 1

#XPRIM_HttpRequest & Base64

Posted: Mon Sep 10, 2018 11:10 am
by soa
I am trying to send a file in a json object using the following code

Define_Com Class(#XPRIM_Binary) Name(#MyFileBinary)
#MyFileBinary.FromFile Path(#ifslnm)
#RootObject.InsertString Key('project') String(#MyFileBinary.AsBase64String)
#Request.Content.AddJsonObject( #RootObject )
#Request.DoPOst( #urlX )

While this runs fine for smaller files I tried it with a 16meg PDF and received the following error

RUNADPRM('DBUG=Y DBHT=lcb1059:51234')
Fatal Error:
Fatal Error : Component : XLB00046 (Internal) Reference to C++ peer
obj Statement : 124 Message : bad allocation Routine : *COMP.

Is there some underlying maximum size for the json object or a component of it.

It seems to be legitimate as json and http and in fact works fine with Lansa Integrator.

Re: #XPRIM_HttpRequest & Base64

Posted: Mon Sep 10, 2018 1:24 pm
by tsupartono
The default memory allocation on IBM i is limited to 16M, so that may be your issue.

We'll investigate to see if there is any way around this limitation.

Note also that if you are writing/reading Base64-encoded file, don't encode/decode manually, as VL strings are limited to 64K - you won't get an error but your base64-encoded will be truncated.
Use instead JsonWriter.

Code: Select all

JsonWriter.WriteBase64StringFromFile  Name('file') FilePath('/tmp/myfile.pdf')
Note that currently it will still not work for files > 16M, but it will work for anything < 16M (whereas if you manually encode the file into base64 string using XPRIM_Binary, your base64 string will be truncated at 64K).

Re: #XPRIM_HttpRequest & Base64

Posted: Mon Sep 10, 2018 3:24 pm
by soa
Thanks for the prompt response Tony. I didn't know about the WriteBase64StringFromFile method.