Question
David Crawford · Feb 20, 2018

REST Data Limit

I'm experimenting with sending large amounts of data in a POST payload to be stored as a stream. However I've noticed that no matter how many characters are in the message, Cache only gets about 32k of them, cutting off the rest. Conversely as expected it can only send about 32k worth of characters in a payload.

Before I get creative, is there a REST message size limit that can be changed? Or is there something else going on here?

Thank you!

1
0 937
Discussion (9)1
Log in or sign up to continue

Aha you're absolutely right. It was so simple, thank you! SizeGet() was accurate and I overrode the Read() default.

What if I need to read something that is beyond the max string length? Do I have to break it up into segments?

Try:

%request.Content.Data.Read($$$MaxStringLength)

If you have json you can cast it into object without reading the stream in user code:

Set obj = {}.%FromJSON(%request.Content.Data)

Same for XML (you can get it from Stream or even from url).

What do you need to do? Many actions can be either performed with streams or there's a workaround.

But ultimately yes, if the stream is beyond max string length (3641144 symbols) you'll need to process it chunk by chunk.

I'm just trying to send a large chunk of characters, have it stored as a stream, and then returned to the client. Thank you for your advice though, I'll figure something out hopefully, at least I know what can be done.

Well, in this case you definitely don't need to read from stream at all. You can save the stream in the database (or file using %Stream.FileCharacter)) and send it to the client later:

set stream = ##class(%Stream.GlobalCharacter).%New()
set sc = stream.CopyFromAndSave(%request.Content)
set oid = stream.%Oid()
kill (oid)
set stream = ##class(%Stream.GlobalCharacter).%Open(oid)
do stream.OutputToDevice()

Streams can be class properties too.

What you've shown me inspired me to try something else...I can't draw from %request.Content.Data directly because it's always undefined, so I've had to use Read() all of the time whenever I need Data values from POST messages.

This seems to be working for any size so far, and I think I can come up with something more efficient later, but at least it's working!

set stream = ##class(%Stream.GlobalCharacter).%New()
While (%request.Content.AtEnd = 0) {
     Set len = $$$MaxStringLength
     do stream.Write(%request.Content.Read(.len))

}

//etc..


Set outputStream = ##class(%Stream.GlobalCharacter).%Open(oid)
While (outputStream .AtEnd = 0) {
     Set len = $$$MaxStringLength
     Write outputStream .Read(.len)
 }

It was an error in the example - Data does not exist.

I now fixed my example.