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")
Comments
Replace
Set tSC1 = tStream.Write(dynObject1.%ToJSON())with:
Do dynObject1.%ToJSON(tStream)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?
I googled "JSON max property size" and found.png)
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)
Do dynObject1.%Set("Stream", request.Stream, "stream")I decided to just send the filename and then the compute pod can Read the file on a shared volume.