Convert Java.Byte.Array to "normal" Arrays to send Binary Data via Cirrus Link MQTT

Hi everyone, I’m hoping to get your opinions on an issue that I faced

I have 2 gateways (A and B). Gateway A needs to send a file to B via Cirrus Link MQTT, so I create a Byte Array tag since Binary Data is not supported by Cirrus Link yet.

So Gateway A wrote to the tag, Gateway B read the tag, but when trying to do system.file.writeFile, it fails with:

TypeError(“writeFile(): 2nd arg can’t be coerced to String, byte”,)

I found out that it’s because Byte Array tags are type “Java.Byte.Array” and Binary Data tags are type “Array.Array”. And system.file.writeFile needs the latter.

So to fix the problem, I changed the receiving tags on Gateway B to Binary Data and left the Gateway A as Byte Array.

So far it’s working but I’m hoping to get some opinions on is it a good solution, or will it cause problem down the line?

If so, are there ways to convert a “Java.Byte.Array” to “Array.Array”? And will Cirrus Link support Binary Data tags soon?

Thanks :thinking:

Google Jython’s jarray module. That can create objects that are low-level java byte[] datatype.

You may need a special hammer to fit an arbitrary Python byte string into a jarray that writeFile likes:

Although, are you aware that MQTT Transmission and MQTT Engine have a general purpose file-transmission mechanism:

Hi thanks guys for the help, in the end we went with the jarray module to convert java arrays to normal arrays.

And we took at the look at the file transfer mechanism, looks really good we weren’t aware of that. But in the end since we were using satelite data we decided not to go with that as it looks like a lot of overhead.

We went for the simple Byte over tag method, and therefore 0 overhead :grin:

Hello All,
I'm reading a file through the FileUpload component and writing it to a variable.
But it is saving with the format array('b', [-31, 58, 11.....]). When I forward the image to the API it returns an error, as it is expecting a binary.

How can I do this conversion? Could someone send me an example, please?

That means you are converting to a string somewhere. That is the problem. You cannot use curly brace parameters in your SQL with these, as curly braces perform string substitution. You must use question mark parameters in a scripted "Prep" query, or value parameters (the colon prefixed named parameters) in a Named Query. That's the only way to push a byte array (or any other values) to SQL without corrupting it in translation.

{ Show us your code and SQL for more precise advice. }