Question
· Jan 22, 2020

%GlobalBinaryStream to %Binary

When reading %GlobalBinaryStream into a %String I am aware therte is a size limit of 3,6MB.

My question is since %Binary is underlying a %String is there a limit on this as well?

Can I safely read any size %GlobalBinaryStream into a %Binary?

Discussion (3)0
Log in or sign up to continue

Hi

The short answer is yes, you are constrained by the 3.6Mb string size limit and bear in mind that if you are exposing that property to SQL and ODBC you are further constrained by the limitations within ODBC itself. 

I have been giving this whole concept a lot of thought recently. My context is slightly different as I am working in the context of FHIR and JSON and for example you can send in a patient's photo which in JSON has to be represented as a string of Base64Encoded Binary . In principal that photo could be of any size but when the JSON string is converted into a FHIR Patient Object the underlying datatype of the photo.data.value is ultimately derived from a class called %xsd.Base64Binary which is esentially a string and therefore has the size limitation. It doesn't really matter what my underlying persisted datatype is i.e. %GlobalBinaryStream because I am working with the IRIS FHIR Classes as intemediary object classes between my JSON and my underlying persisted classes I have to work with the constraint that the JSON Base64Binary content will fail if it's length exceeds the 3.6Mb (something I wish to address with ISC/WRC at some point).

The alternative of course, to persisting larger data content of something link an image, is to have a url that points to the image location and can be retrieved from the image server for presentation purposes.

So where I know that my images are not going to be that large I read in or write out the base64binary from/to my JSON message but where I know the image is larger such as an x-ray or histo image then that content lives on the appropriate image server as is retirieved  when required for presentation purposes.

Nigel Salm

Hi Nigel.

I hasten to inform you that new classes have been added to IRIS for writing/reading streams in JSON format: %Stream.DynamicBinary, %Stream.DynamicCharacter.

 

Here is a sample code:

Result:

USER>##class(dc.test).test()
[Export] len(string): 3641129, len(cs): 7282288
 
1. [Import    %DynamicObject] len(longstring): 3641129, len(cstream): 7282288
2. [Import %RegisteredObject] len(string): 3641129, len(cs): 7282288
3. [Import %RegisteredObject] len(string): 3641129, len(cs): 7282288

Patch for 2019.1.1CE:

Instead of

        $$$GENERATE(indent_"  Set sc=stream.Write(%JSONObject."_$$$QN($$$jsonfieldname(propertyMap))_") If $$$ISERR(sc) Goto %JSONImportExit")

need

        $$$GENERATE(indent_"  Set testInvalidField=0, sc=stream.CopyFrom(%JSONObject.%Get(field,,""stream"")) If $$$ISERR(sc) Goto %JSONImportExit")

It is possible that in version 2019.4.x has already fixed everything.