# Converting return data of event.file.getBytes to a scalar format

**URL:** <https://forum.inductiveautomation.com/t/converting-return-data-of-event-file-getbytes-to-a-scalar-format/103168>\
**Category:** Ignition\
**Tags:** scripting, ignition81, perspective\
**Created:** [March 3, 2025, 8:34pm UTC](https://forum.inductiveautomation.com/t/converting-return-data-of-event-file-getbytes-to-a-scalar-format/103168 "2025-03-03T20:34:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![richhull](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@richhull](https://forum.inductiveautomation.com/u/richhull)\
**Post date:** [March 3, 2025, 8:34pm UTC](https://forum.inductiveautomation.com/t/converting-return-data-of-event-file-getbytes-to-a-scalar-format/103168/1 "2025-03-03T20:34:14Z")

</div>

I am currently trying to write a script on my file upload component. However, when I pass in the uploaded data it does print out using system.perspective.print() in the format I want (scalar). However when I try to save or store the data further in the script, it still remains in its original byte dataset format. Is there any way I can convert it to the scalar version for storage based purposes? I do not want a 2MB array on my ignition.

I want this which is printed out:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/2/a29e4b77eb6df682cf2a688d5a1de1da1021810e.png)

But I keep getting this:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/9/b937caec6f781e8db8c413cb558e80d09f3efeb7.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 3, 2025, 8:50pm UTC](https://forum.inductiveautomation.com/t/converting-return-data-of-event-file-getbytes-to-a-scalar-format/103168/2 "2025-03-03T20:50:38Z")

</div>

`event.file.getBytes()`, as documented, returns a raw Java byte array. There is no more fundamental type for it to be returned as - it's literally the binary data that was the uploaded file.

What that format lacks is a specific string presentation, because turning binary bytes into a string is an _encoding_ operation, and there are infinitely many possible ways you _could_ encode those bytes.

You probably, if you are storing into a database or as a file, do not want to do _any_ encoding. You should only encode if you actually have to output as a string somewhere, and you **must** choose a format that can reliably encode arbitrary bytes, such as base64; if you try to ASCII or UTF-8 encode a random binary file you'll get at best garbage and at worst lose significant portions of your data.

Show the rest of the script you're actually using, and describe where you're trying to store these uploaded files.

---

<div class="post-metadata">

**Author:** ![richhull](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@richhull](https://forum.inductiveautomation.com/u/richhull)\
**Post date:** [March 21, 2025, 5:47pm UTC](https://forum.inductiveautomation.com/t/converting-return-data-of-event-file-getbytes-to-a-scalar-format/103168/3 "2025-03-21T17:47:47Z")

</div>

Sorry for the late reply, I am using this data to create a form for people to fill out and at the end add images or PDFs to it.  
My main concern with the byte array compared to the other is that one is 2MB of data while the other is 577 kB and I do not want to bog down the gateway. Is there a better alternative to what I am trying to accomplish?

---

<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:** [March 21, 2025, 6:06pm UTC](https://forum.inductiveautomation.com/t/converting-return-data-of-event-file-getbytes-to-a-scalar-format/103168/4 "2025-03-21T18:06:01Z")

</div>

I suspect you are assigning the byte array to a Perspective property. That breaks it. Perspective properties cannot hold arbitrary objects, and your byte array is being wrapped into a Perspective array.

Put the original byte array directly into your database. Do not access it in Perspective at all. Rely on the WebDev or Blob server to deliver bytes to your Image or IFrame components.

---

<div class="post-metadata">

**Author:** ![richhull](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@richhull](https://forum.inductiveautomation.com/u/richhull)\
**Post date:** [March 21, 2025, 7:26pm UTC](https://forum.inductiveautomation.com/t/converting-return-data-of-event-file-getbytes-to-a-scalar-format/103168/5 "2025-03-21T19:26:39Z")

</div>

Oh ok so I should create a temporary holding db to store the image data and when the user submits the form transfer the info to the main db and delete it from the temporary db?

---

<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:** [March 21, 2025, 7:32pm UTC](https://forum.inductiveautomation.com/t/converting-return-data-of-event-file-getbytes-to-a-scalar-format/103168/6 "2025-03-21T19:32:03Z")

</div>

I wouldn't transfer. Make a table just for image data. Four columns: ID, timestamp, content, and content type (to support different image formats). Carry the ID in your form progress, not the bytes. At form submission time, include the ID in the main table for the process as a foreign key to the images table.

For images that get uploaded but never attached to a completed form, run a clean up query that deletes images that aren't referenced from the main table and are some number of days old.

(Maybe a fifth column for the user who uploaded. So you can report how many abandoned images belong to particular users.)

---

<div class="post-metadata">

**Author:** ![richhull](https://avatars.discourse-cdn.com/v4/letter/r/b19c9b/32.png) [@richhull](https://forum.inductiveautomation.com/u/richhull)\
**Post date:** [March 21, 2025, 7:52pm UTC](https://forum.inductiveautomation.com/t/converting-return-data-of-event-file-getbytes-to-a-scalar-format/103168/7 "2025-03-21T19:52:54Z")

</div>

It worked great! Thank You!
