Martin Staudigel · Jan 24

Returning Data from a %CSP.Page

Hello Community,

to return data from the OnPage() method of a %CSP.Page I used to simply write out the value of a %DynamicArray e.g. via

write tResponse.%ToJSON()

and return $$$OK afterwards.

Large objects bigger than 4MB result in an exception when trying to create return values using this way. What is best practice for returning values as JSON, especially if values exceeding the capcity of the %String class are to be expected? I saw that it is possible to write data to a file with e.g.:

set tmp = tResponse.%ToJSON("/opt/home/tmp/test_stream.txt")

Am I supposed to do this and afterwards something like this to write out data MB wise (did not try yet, if this code works - it's just an idea)?

set tStreamIn = ##class(%Stream.FileBinary).%New()
set tSc tStreamIn.FilenameSet("/opt/home/tmp/test_stream.txt")
while (' tStreamIn.AtEnd ) {
  write tStreamIn.Read(1048576)

Is it ok do handle big data like this or is there another (better) way recommended?

Thanks for your help, regards,


Product version: IRIS 2021.1
$ZV: IRIS for UNIX (SUSE Linux Enterprise Server for x86-64) 2021.1 (Build 215U) Wed Jun 9 2021 09:48:27 EDT
0 108
Discussion (3)1
Log in or sign up to continue

%ToJSON has three ways. One of the is to output through String, as you did with Write command.

In your case you can simply use Do command instead, and it will just output to the current device directly, without collecting it to a limited variable.

Or you can do through the stream, passed as a first parameter

So, you mean replacing

write tResponse.%ToJSON()


do tResponse.%ToJSON()

will do the job, even for big responses? That would be great.

Thank you,