#XPRIM_HttpRequest & Base64

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
soa
Posts: 289
Joined: Mon Dec 07, 2015 3:15 pm

#XPRIM_HttpRequest & Base64

Post by soa » Mon Sep 10, 2018 11:10 am

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.

tsupartono
Posts: 74
Joined: Wed Jan 25, 2017 11:12 am

Re: #XPRIM_HttpRequest & Base64

Post by tsupartono » Mon Sep 10, 2018 1:24 pm

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).

soa
Posts: 289
Joined: Mon Dec 07, 2015 3:15 pm

Re: #XPRIM_HttpRequest & Base64

Post by soa » Mon Sep 10, 2018 3:24 pm

Thanks for the prompt response Tony. I didn't know about the WriteBase64StringFromFile method.

Post Reply