How to Output Binary Data with REST

Hello!

My goal is to serve files using REST classes only (no filesystem should be used), and I am a halfway far from it.

What I am succeeded in, is serving character files (html/css/javascript/etc) using the next approach:

1. Encode the file to Base64 and put it into XData block, like this:

/// css/index.css
XData File0 [ MimeType = text/css ]
{
QGNoYXJzZXQgIlVURi04Ijsjd2luZG93cyxib2R5LGh0bWx7cG9zaXRpb246cmVsYXRpdmU7b3ZlcmZsb3c6aGlkZGVufWJ1dHRvbixpbnB1dFt0eXBlPWJ1dHRvbl0sdGFibGUgdGh7YmFja2dyb3VuZC1jb2xvcjojMDJhZDhiO2NvbG9yOiNmZmZ9I3dpbmRvd3MsLmNlbnRyYWwsYm9keSxodG1se3dpZHRoOjEwMCU7aGVpZ2h0OjEwMCV9I2dyYXBoIC5ub2RlcyAubm9kZSwjdGFidWxhciB0aCwjdGFidWxhciB0cixidXR0b24saW5wdXRbdHlwZT1idXR0b25dLGlucHV0W3R5cGU9Y2hlY2tib3hdLGxhYmVsLHNlbGVjdHtjdXJzb3I6cG9pbnRlcn1ib2R5LGh0bWx7bWFyZ2luOjA7cGFkZGluZzowO2ZvbnQtZmFtaWx5Om1vbm9zcGFjZX1pbnB1dFt0eXBlPW51bWJlcl0saW5wdXRbdHlwZT10ZXh0XSxzZWxlY3R7YmFja2dyb3VuZDowIDA7Y29sb3I6aW5oZXJpdDtmb250OmluaGVyaXQ7dGV4dC1zaGFkb3c6aW5oZXJpdH0jd2luZG93c3t0b3A6MDstd2Via2l0LXRyYW5zaXRpb246YWxsIC4zcyBlYXNlOy1tb3otdHJhbnNpdGlvbjphbGwgLjNzIGVhc2U7LW1zLXRyYW5zaXRpb246YWxsIC4zcyBlYXNlOy1vLXRyYW5zaXRpb246YWxsIC4zcyBlYXNlO3RyYW5zaXRpb246YWxsIC4zcyBlYXNlfSN3aW5kb3dzLm9mZlNjcmVlbnt0b3A6MTAwJTtvdmVyZmxvdzp2aXNpYmxlfXRhYmxle2JvcmRlci1zcGFjaW5nOjA7Ym9yZGVy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ZnQ6OXB4IHNvbGlkICMwMDB9LmhpbnQ+LnRvb2x0aXA6aG92ZXJ7b3ZlcmZsb3c6dmlzaWJsZX0uaGludD4udG9vbHRpcDpob3Zlcj4ubGFiZWx7dmlzaWJpbGl0eTp2aXNpYmxlO3JpZ2h0OjEwMCU7bWFyZ2luLXRvcDotMTVweDttYXJnaW4tcmlnaHQ6MTVweDt6LWluZGV4Ojk5OTtvcGFjaXR5Oi44fS5oaW50Pi50b29sdGlwLnJpZ2h0Pi5sYWJlbDphZnRlcntsZWZ0OmF1dG87cmlnaHQ6MTAwJTtib3JkZXItbGVmdDpub25lO2JvcmRlci1yaWdodDo5cHggc29saWQgIzAwMH0uaGludD4udG9vbHRpcC5yaWdodDpob3Zlcj4ubGFiZWx7cmlnaHQ6YXV0bztsZWZ0OjEwMCU7bWFyZ2luLXJpZ2h0OjA7bWFyZ2luLWxlZnQ6MTVweH0uaGludD4udG9vbHRpcC50b3A+LmxhYmVse3RvcDotMjBweDt3aWR0aDoxNjBweDtib3gtc2l6aW5nOmJvcmRlci1ib3g7bGVmdDpjYWxjKC04MHB4ICsgNTAlKX0uaGludD4udG9vbHRpcC50b3A+LmxhYmVsLnR3by1saW5le3RvcDotMzNweH0uaGludD4udG9vbHRpcC50b3A+LmxhYmVsOmFmdGVye3JpZ2h0OmF1dG87dG9wOmNhbGMoMTAwJSArIDZweCk7bGVmdDpjYWxjKDUwJSAtIDhweCk7Ym9yZGVyLWJvdHRvbTpub25lO2JvcmRlci10b3A6OHB4IHNvbGlkICMwMDA7Ym9yZGVyLXJpZ2h0OjhweCBzb2xpZCB0cmFuc3BhcmVudDtib3JkZXItbGVmdDo4cHggc29saWQgdHJhbnNwYXJlbnR9LmhpbnQ+LnRvb2x0aXAudG9wOmhvdmVyPi5sYWJlbHtyaWdodDphdXRvO21hcmdpbi1yaWdodDowO21hcmdpbi1sZWZ0OjB9
}

2. Make the endpoint which will serve this file, like this (simplified):

XData UrlMap
{
<Routes>
    <Route Url="/file" Method="GET" Call="StaticDelivery"/>
</Routes>
}

ClassMethod StaticDelivery() As %Status
{
    set xdata = ##class(%Dictionary.CompiledXData).%OpenId($ClassName()_"||File0")
    set %response.CharSet = "utf-8"
    set %response.ContentType = xdata.MimeType
    write $System.Encryption.Base64Decode($zcvt(xdata.Data.Read(xdata.Data.Size), "O", "UTF8"))
    return $$$OK
}

And this does work perfectly!

However, when it turns to serving binary files (fonts, images, etc) with the same approach, they are seemed to be corrupted (some differences are highlighted):

It seems what simply writeing the binary data is not the good idea.

Is there anything which actually can write the binary data to the client?

P.S.

Indeed I have discovered %CSP.StreamServer class which was able to do this job (example). But the approach I used in the example unfortunately works only with file streams. Any attempts to put BinaryStreams OIDs to Encrypt method resulted with the same behavior as just writeing this with REST, which gives corrupted files.

P.P.S.

The font file in Base64 which I wanted to serve:

/// fonts/iknowentitybrowsericons.woff
XData File7 [ MimeType = application/font-woff ]
{
d09GRk9UVE8AABHEAAsAAAAAG5QAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABDRkYgAAABCAAADjcAABWzF/9WL0ZGVE0AAA9AAAAAGgAAABx2NdoUR0RFRgAAD1wAAAAdAAAAIABIAARPUy8yAAAPfAAAAEcAAABgUB1eu2NtYXAAAA/EAAAAdAAAAX5y11M1aGVhZAAAEDgAAAApAAAANgsWeEFoaGVhAAAQZAAAABgAAAAkBC8CA2htdHgAABB8AAAALgAAADoGLQIcbWF4cAAAEKwAAAAGAAAABgAbUABuYW1lAAAQtAAAAQAAAAJGmZHlu3Bvc3QAABG0AAAAEAAAACAAAwABeJzFWH1sW9d1f5T1yBvZlZtML0g3zY6drkGwOs7WeGj7R9C6QDPMTfZHUttxly0ORVmy9UnRJmmRFMn3yXfe93v8ECWRjvXhSrFj2UqCekstx38MGBQgw+wBAYpuCwKkQbcuwOrhEaCB7rxHy7KS2v/uUnq8797zdc8959zfZYBqb6cCgcBj/SeGhuORoVh/LPl6dDg+Fon2h4eHxqhAGxWgvt94tq2xb0vjsXZlWwC2bYFt7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KrWqGrvX2dXK29PZOyY3692FtQmu9k3WlrjbrB/0PcWp4nGNgZkAGjAxoAAAAjgAF
}

Many thanks for any help!

Answers

With your xdata block, this works:

ClassMethod GetFile() as %Status {
    set xdata = ##class(%Dictionary.CompiledXData).%OpenId($ClassName()_"||File7")
    s %response.Status=200
    s %response.ContentType="application/octet-stream"
    write $System.Encryption.Base64Decode(xdata.Data.Read(xdata.Data.Size))
    q $$$OK
}

Hilarious! I spent a half of my day for this issue, and it turned out that

set %response.CharSet = "utf-8"

Was the only problem which needed to be deleted. Thank you so much Fabian!

This works for me for a file from the FS:

ClassMethod GetFile() as %Status {
    s file=##class(%Stream.FileBinary).%New()
    s file.Filename="/tmp/Psi-0.15.dmg"
    s %response.Status=200
    s %response.ContentType="application/octet-stream"
    while ('file.AtEnd) {
        w file.Read(10000)
    }
    q $$$OK
}

instead of using a magic number 10000, it would be better to use a macro $$$MaxLocalLength, see %Stream.FileBinary:ReadLine