Save FHIR Attachment data without decoding and again encoding

Primary tabs

We have a situation where we want to save the patient photo (or any other attachment) received via FHIR to a persistent property without decoding it. When it is sent out again using FHIR is is stored in the encoded format and need not be encoded. We do not need to decode it for our application. We always use it on another system that retrieves it or saves it via FHIR and therefore it is always received or sent embedded in JSON.

The problem is that the FHIR attachment automatically encodes the attachment data in HSFHIRToFHIR, but it does not do the opposite when the attachment is received; that is in FHIRToHSFHIR it does not decode. This is causing a problem for us, we now HAVE to store this decoded and the image retrieval takes a long time. 

What was the intended use of attachments with FHIR in relation to storing it as persistent data. Our persistent property is of type %Stream.GlobalBinary.

How was it intended this be used? How do we decode an image larger than the InterSystems string length allows? Why is it encoded automatically and how to get around that?