# Perspective save getBytes() into parameters as ArrayWrapper

**URL:** <https://forum.inductiveautomation.com/t/perspective-save-getbytes-into-parameters-as-arraywrapper/41646>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 18, 2020, 2:26pm UTC](https://forum.inductiveautomation.com/t/perspective-save-getbytes-into-parameters-as-arraywrapper/41646 "2020-12-18T14:26:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [December 18, 2020, 2:26pm UTC](https://forum.inductiveautomation.com/t/perspective-save-getbytes-into-parameters-as-arraywrapper/41646/1 "2020-12-18T14:26:25Z")

</div>

When I call the getBytes() on a perspective file upload I get the expected type of array.array. However if I move that getBytes() array to a param and then look at the ensuing type I get com.inductiveautomation.perspective.gateway.script.PropertyTreeScriptWrapper$ArrayWrapper.

How to I then take that param and later form it back to an array so I can pass it off to SQL to save as a longblob/varbinary(MAX)?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 18, 2020, 2:47pm UTC](https://forum.inductiveautomation.com/t/perspective-save-getbytes-into-parameters-as-arraywrapper/41646/2 "2020-12-18T14:47:39Z")

</div>

Based on this:

[https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.0/com/inductiveautomation/perspective/gateway/script/PropertyTreeScriptWrapper.ArrayWrapper.html](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.0/com/inductiveautomation/perspective/gateway/script/PropertyTreeScriptWrapper.ArrayWrapper.html)

, you can’t get to the original array again. ):

However, jython is often smart enough to construct raw java byte arrays when passing sequences into java APIs. Meaning, you might just be able to pass it to a PrepUpdate() and let JDBC have at it.

Otherwise, you’ll have to use the [jarray](https://www.jython.org/jython-old-sites/archive/21/docs/jarray.html) module to reconstruct the plain byte array again.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [December 18, 2020, 2:50pm UTC](https://forum.inductiveautomation.com/t/perspective-save-getbytes-into-parameters-as-arraywrapper/41646/3 "2020-12-18T14:50:14Z")

</div>

~~So I ended up figuring it out after another cup of coffee.~~

~~I wrapped the param in list() and the JDBC driver was able to interpret what I wanted it to do thankfully.~~

~~Sucks that once it hits the params we can get it back to the original datatype. Oh well.~~

Spoke to soon. As a list it didn’t go into the database as a blob so I couldn’t pull it back out as a usable file. So back to the drawing board…

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 18, 2020, 3:01pm UTC](https://forum.inductiveautomation.com/t/perspective-save-getbytes-into-parameters-as-arraywrapper/41646/4 "2020-12-18T15:01:22Z")

</div>

> [@pturmel](#):
>
> **you’ll have to use the [jarray](https://www.jython.org/jython-old-sites/archive/21/docs/jarray.html) module**

Pass the wrapper (which implements a python sequence) to the jarray module with the 'b' type code.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 18, 2020, 3:04pm UTC](https://forum.inductiveautomation.com/t/perspective-save-getbytes-into-parameters-as-arraywrapper/41646/5 "2020-12-18T15:04:10Z")

</div>

BTW, why do you put it in a param? Unless it is private, that will make it go back to the browser, but as json. Blegh. Cache it in a script module dictionary if you can’t send it directly to the database. That’ll keep it in the gateway as a normal byte array.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [December 18, 2020, 3:07pm UTC](https://forum.inductiveautomation.com/t/perspective-save-getbytes-into-parameters-as-arraywrapper/41646/6 "2020-12-18T15:07:29Z")

</div>

No real good reason why. I just familiar with the params and it makes things a bit easier.

For the second option would it be as simple as this?

```auto
_fileBytes = []
def fileBytes()
    return _fileBytes

```

and then just use it as:

```auto
shared.fileBytes().append(newFileBytes)

```

Or am I missing something?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 18, 2020, 3:13pm UTC](https://forum.inductiveautomation.com/t/perspective-save-getbytes-into-parameters-as-arraywrapper/41646/7 "2020-12-18T15:13:24Z")

</div>

Yes, but you’ll probably want a .clear() in there. Also note that doing it just like that will have it shared across all sessions. You probably want a dictionary at the top level with session ids for keys, and save a (timestamp, bytes) tuple. Then use a gateway timer to clean out stale entries.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [December 18, 2020, 3:14pm UTC](https://forum.inductiveautomation.com/t/perspective-save-getbytes-into-parameters-as-arraywrapper/41646/8 "2020-12-18T15:14:38Z")

</div>

Thanks for the help!

The jarray worked and so I know proof of concept is sound. So I’ll start working on the better alternative solution.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 18, 2020, 3:17pm UTC](https://forum.inductiveautomation.com/t/perspective-save-getbytes-into-parameters-as-arraywrapper/41646/9 "2020-12-18T15:17:34Z")

</div>

Also note that you don’t need a function to gain access to the top-level object. If you have this in `myModule`:

```auto
fileBytesMap = {}

```

You can just access `myModule.fileBytesMap[someKey]` anywhere.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [December 18, 2020, 3:18pm UTC](https://forum.inductiveautomation.com/t/perspective-save-getbytes-into-parameters-as-arraywrapper/41646/10 "2020-12-18T15:18:22Z")

</div>

Cool… didn’t know that.
