Written by

Integration Engineer at Cognosante
Question Oliver Wilms · Apr 13, 2023

Read a long Stream into JSON Dynamic Object - MAXSTRING error

I am trying to read binary data from HTTP Request Stream and build a Dynamic Object with multiple properties. I am getting MAXSTRING error with this code:

 Set dynObject1 = ##class(%DynamicObject).%New()
 Set dynObject1.OriginalFilename = $P($P(request.HTTPHeaders.GetAt("RawParams"),"&",2),"=",2)
 Set dynObject1.SiteId = $P($P(request.HTTPHeaders.GetAt("RawParams"),"&",1),"=",2)
 For {
   Set len = 1000000
   Set tRead = request.Stream.Read(.len,.sc)
   Set ^TESTutil($INCREMENT(^TESTutil),"len") = len
   Set ^TESTutil($INCREMENT(^TESTutil),"sc") = $Get(sc)
   If (len < 1) Quit }
   Set dynObject1.Stream = dynObject1.Stream_tRead
   Set len = $Length(dynObject1.Stream)
   Set ^TESTutil($INCREMENT(^TESTutil),"len2") = len
 }
 Set tStream = ##class(%Stream.GlobalCharacter).%New()
 Set tSC1 = tStream.Write(dynObject1.%ToJSON())
 Set ^TESTutil($INCREMENT(^TESTutil),"tSC1") = tSC1
 Set tSC2 = tStream.%Save()
 Set ^TESTutil($INCREMENT(^TESTutil),"tSC2") = tSC2
 Set context.GenericMessage = ##class(EnsLib.HTTP.GenericMessage).%New(tStream)
 Do context.GenericMessage.SetHTTPHeaders("URL=cdw/api/file/new")
 

Product version: IRIS 2022.2

Comments

Eduard Lebedyuk · Apr 14, 2023

Replace

Set tSC1 = tStream.Write(dynObject1.%ToJSON())

with:

Do dynObject1.%ToJSON(tStream)
0
Oliver Wilms  Apr 14, 2023 to Eduard Lebedyuk

My dynamic object contains three properties, like this:

Set dynObject1.Filename = "myzipfile.gz"

Set dynObject1.SiteId = "123"

But how can I say dynObject1.Stream = request.Stream which contains large binary stream?

0
Robert Cemper  Apr 14, 2023 to Oliver Wilms

I googled "JSON max property size" and found

So whoever is the recipient, there will be troubles with larger properties
I'd look for something to chop it into smaller pieces. (elephant approach)

0
Eduard Lebedyuk  Apr 15, 2023 to Oliver Wilms
Do dynObject1.%Set("Stream", request.Stream, "stream")
0
Oliver Wilms · Apr 18, 2023

I decided to just send the filename and then the compute pod can Read the file on a shared volume.

0