Question
· Jan 24, 2022

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,

Martin

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
Discussion (3)1
Log in or sign up to continue