Page 1 of 1

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

Posted: Mon Apr 18, 2022 8:23 pm
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

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

Posted: Mon Apr 18, 2022 10:21 pm
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

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

Posted: Tue Apr 19, 2022 12:58 am
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

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

Posted: Wed Apr 20, 2022 5:36 pm
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?

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

Posted: Wed Apr 20, 2022 11:19 pm
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.