End-to-End Streaming File Downloads in Perspective

As part of a broader project, I need to download files to a Perspective session that exist in the Gateway server's filesystem. These files may be quite large, so I would prefer to avoid loading them entirely into Gateway memory before downloading if at all possible.

I am currently using system.file.readFileAsBytes(...) to obtain the raw data from the file and passing that to system.perspective.download(...), but of course the entire byte array is loaded at once.

system.perspective.download(...) indicates that it also accepts an InputStream datasource, but the API documentation is unclear as to whether this provides end-to-end data streaming to the Perspective session or if it still buffers the file in Gateway memory before pushing to session. Anyone have insight/experience with this?

Versions: 8.1.xx, 8.3.xx

Thanks in advance!

It will directly stream the bytes.
The 'download' function works by essentially mounting a temporary URL on the gateway webserver, then instructing the frontend session to open a connection to that URL. Once the frontend does that, the backend will invoke the callback, which will, if you passed in an input stream, resolve the bytes/string/inputstream you provided.

Awesome, thank you!

If I'm understanding correctly, in that case the download function paired with an InputStream object should be able to download arbitrarily large files with negligible/"constant" memory overhead, right?

In theory, yes. I'd recommend using Java's nio/files API to get your input streams.