Ignition Perspective file download

When trying to download a ZIP file via system.file.readFileAsBytes, I get the error:

Size cannot be greater than Integer max value: 3488226777

I don't see another Perspective function other than readFileAsBytes, is it possible to use Java functions instead inside the script to allow for downloading large files?

Can you show some code?

The function you mentioned doesn't do the action you're describing.

Yes, this is the script. It pulls the filename from a filetree then downloads it. Small file sizes work, but files greater than 2-3Gb don't work:

filename = result[0]['fileLocation'].split('\')[-1]
data = system.file.readFileAsBytes(result[0]['fileLocation'])
system.perspective.download(filename, data)

The error in full is:

Error running action 'component.onActionPerformed' on Report/file share@C$0:0/root/download: Traceback (most recent call last): File "function:runAction", line 2, in runAction File "", line 11, in download at org.apache.commons.io.IOUtils.toByteArray(IOUtils.java:467) at org.apache.commons.io.FileUtils.readFileToByteArray(FileUtils.java:1675) at com.inductiveautomation.ignition.common.script.builtin.FileUtilities.readFileAsBytes(FileUtilities.java:144) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Size cannot be greater than Integer max value: 3488226777

Tip: format the code as code rather than as a quote. See Wiki - how to post code on this forum. It will catch you out on Python and general code indentation.

readFileAsBytes returns a primitive Java byte[] under the hood. Java arrays are limited to 32 bit signed integer keys; thus the largest a Java byte array can be is 2,147,483,647 bytes.

But...what on earth are you serving up via Perspective that's (often) greater than 2gB, and how has your gateway not exploded from loading these massive byte arrays into memory?

There's no way to 'stream' massive result sets to consumers entirely via Perspective, which is absolutely what you'd want to do here for performance. I would strongly advocate setting up a 'reverse proxy' software on your gateway in front of Ignition that's capable of (efficiently) hosting these large files.

2 Likes