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
LANSA REQUEST(X_RUN) PROCESS(MCAT001) FUNCTION(GCAT0Y7) PARTITION(V40) X
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.
#XPRIM_HttpRequest & Base64
Re: #XPRIM_HttpRequest & Base64
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.
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).
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')
Re: #XPRIM_HttpRequest & Base64
Thanks for the prompt response Tony. I didn't know about the WriteBase64StringFromFile method.