documentation for #XPRIM_JsonWriter (WriteBase64StringFromFile ) or #PRIM_JSON.Writer (WriteBase64)

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
faridah.belandres
Posts: 11
Joined: Wed Jul 13, 2016 1:57 pm

documentation for #XPRIM_JsonWriter (WriteBase64StringFromFile ) or #PRIM_JSON.Writer (WriteBase64)

Post by faridah.belandres »

Hi,

Good day!
I would like to ask if there is a documentation available for #XPRIM_JsonWriter or #PRIM_JSON.Writer ?
I am trying to build a JSON Request and use the WriteBase64StringFromFile but I think it may have a limitation when it comes to size of the file.
It works for small files but when the file is around around 60+KB or larger, it fails. [or maybe I am not using it correctly]


Below is a sample on how I use it:

Code: Select all

Define_Com Class(#XPRIM_JsonWriter) Name(#JsonWriter)
Define_Map For(*INPUT) Class(#XPRIM_Json) Name(#RequestJson)
Define_Com Class(#XPRIM_HttpRequest) Name(#Request)
Define_Com Class(#XPRIM_UriBuilder) Name(#RequestUrl)
...
#JsonWriter.BeginObject Name('documentDetails')
#JsonWriter.WriteString Name('name') Value('TestFile_20220414')
#JsonWriter.WriteBase64StringFromFile Name('documentContent') Filepath('c:/temp/test/TestFile_20220414.pdf')
#JsonWriter.EndObject
...
#RequestJson.ParseString String(#JsonWriter.AsString)
#Request.Clear
#RequestUrl.Clear
#Request.Content.AddJson Value(#RequestJson)
...
#Request.DoPost Url(#RequestUrl)

I need to use the RequestJson as content for my post request.

I also tried using #PRIM_JSON.Writer 's WrieBase64 like this:

Code: Select all

Define_Com Class(#PRIM_IOC.StringWriter) Name(#StringWriter)
Define_Com Class(#PRIM_JSON.Writer) Name(#Writer) Textwriter(#StringWriter)
Define_Com Class(#XPRIM_File) Name(#OutFile)
#OutFile.SetPath Filepath('c:/temp/test/Todo.txt')
#Writer.WriteBase64 Membername('documentContent') Value(#OutFile)
But I think Writebase64 only encodes to Base64 the path of the file and not the file content.[or I may be mistaken]

A link to a documentation for #XPRIM_JsonWriter (WriteBase64StringFromFile ) or #PRIM_JSON.Writer (WriteBase64) or any info/help would be much appreciated.
Or suggestions on how to use it or sample code would also be nice.


Thank you in advance,
Faridah
sotis
Posts: 16
Joined: Thu Sep 16, 2021 11:37 pm

Re: documentation for #XPRIM_JsonWriter (WriteBase64StringFromFile ) or #PRIM_JSON.Writer (WriteBase64)

Post by sotis »

Hello,

I found this similar question in the forum

viewtopic.php?t=1882
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).
maybe it will help

best,
Sotiris
faridah.belandres
Posts: 11
Joined: Wed Jul 13, 2016 1:57 pm

Re: documentation for #XPRIM_JsonWriter (WriteBase64StringFromFile ) or #PRIM_JSON.Writer (WriteBase64)

Post by faridah.belandres »

Hi Sotiris,

Thank you very much for your reply and for the link.
I think that should be okay with me because the files I'm planning to use are less than or equal to 15MB .
If that is the case, I think the cause of my issue may be this line:

#RequestJson.ParseString String(#JsonWriter.AsString)

I will try to use:
#JsonWriter.SetOutputToHttpRequest Httprequest(#Request)

instead of:
#RequestJson.ParseString String(#JsonWriter.AsString)
#Request.Content.AddJson Value(#RequestJson)

Hopefully it would work this time.


Thank you and regards,
Faridah
jimwatterson
Posts: 56
Joined: Thu Jul 09, 2020 8:31 am

Re: documentation for #XPRIM_JsonWriter (WriteBase64StringFromFile ) or #PRIM_JSON.Writer (WriteBase64)

Post by jimwatterson »

I wish to perform the reverse of this activity. I have a json response containing a base 64 string representation of a file and I need to save it. There doesn't seem to be a ReadBas64StringTofile method on JSONReader.

Anyone have a clue?
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: documentation for #XPRIM_JsonWriter (WriteBase64StringFromFile ) or #PRIM_JSON.Writer (WriteBase64)

Post by Dino »

I did this before to handle a similar situation:
viewtopic.php?f=3&t=2418&p=6951&hilit=json#p6951

and also found this other thing:
viewtopic.php?f=3&t=2400&p=6867&hilit=b ... ring#p6867

I think the later should work for you.
Post Reply