# FileUpload Component: Trying to get the byte string in base64 format

**URL:** <https://forum.inductiveautomation.com/t/fileupload-component-trying-to-get-the-byte-string-in-base64-format/78282>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [August 23, 2023, 1:19pm UTC](https://forum.inductiveautomation.com/t/fileupload-component-trying-to-get-the-byte-string-in-base64-format/78282 "2023-08-23T13:19:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveRNeal](https://avatars.discourse-cdn.com/v4/letter/d/53a042/32.png) [@DaveRNeal](https://forum.inductiveautomation.com/u/DaveRNeal)\
**Post date:** [August 23, 2023, 1:19pm UTC](https://forum.inductiveautomation.com/t/fileupload-component-trying-to-get-the-byte-string-in-base64-format/78282/1 "2023-08-23T13:19:11Z")

</div>

Good morning,

I'm attempting to get the base64 string of a file that I'm uploading using Ignition's FileUpload component, however there doesn't seem to be a list of string formats available to the event.file.getString() function in [this page](https://docs.inductiveautomation.com/display/DOC81/Perspective+-+File+Upload+Scripting). Is there a list of formats handy, and if base64 isn't available for that function, is there a way I can encode the bytes to a base64 string? I've attempted the below code but get the following error "TypeError('b2a\_base64() argument 1 must be bytes or Unicode, not com.inductiveautomation.perspective.gateway.script.PropertyTreeScriptWrapper$ArrayWrapper',)"

```auto
import base64

path = event.file.name
bytes = event.file.getBytes()

#documentation says this returns UTF-8 format, not sure how to get to base64
defaultByteString = event.file.getString() 

base64String = base64.b64encode(bytes) #returns TypeError

```

---

<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:** [August 23, 2023, 3:25pm UTC](https://forum.inductiveautomation.com/t/fileupload-component-trying-to-get-the-byte-string-in-base64-format/78282/2 "2023-08-23T15:25:26Z")

</div>

Don't use jython's base64. Use java's [Base64](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Base64.html).

```auto
from java.util import Base64

def toB64(bytes):
	return Base64.getEncoder().encodeToString(bytes)

```

In your upload event:

```auto
b64str = someLibrary.toB64(event.file.getBytes())

```

---

<div class="post-metadata">

**Author:** ![DaveRNeal](https://avatars.discourse-cdn.com/v4/letter/d/53a042/32.png) [@DaveRNeal](https://forum.inductiveautomation.com/u/DaveRNeal)\
**Post date:** [August 24, 2023, 2:30pm UTC](https://forum.inductiveautomation.com/t/fileupload-component-trying-to-get-the-byte-string-in-base64-format/78282/3 "2023-08-24T14:30:17Z")

</div>

That did the trick, thank you!

---

<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:** [August 24, 2023, 2:41pm UTC](https://forum.inductiveautomation.com/t/fileupload-component-trying-to-get-the-byte-string-in-base64-format/78282/4 "2023-08-24T14:41:41Z")

</div>

You're welcome.

Tip: any time you reach for the jython standard library's importable modules to solve some problem involving bytes, strings, sockets, web APIs, dates, times, and calendars--STOP. Look up the java way to do the corresponding task and call those java classes from jython.

Jython's python2 heritage means its stdlib doesn't separate bytes from strings properly, even though java does. And its python2.7 stdlib lacks many other updates and bugfixes that, while purely pythonic, only exist in python3. And the jython `socket` library has been an utter disaster, carrying through into anything that depends on it.

---

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [August 24, 2023, 2:58pm UTC](https://forum.inductiveautomation.com/t/fileupload-component-trying-to-get-the-byte-string-in-base64-format/78282/5 "2023-08-24T14:58:22Z")

</div>

It was actually this thread that inspired me to try and rewrite my [zip code](https://forum.inductiveautomation.com/t/perspective-download-zip-file-with-several-files-inside/75035/5) from python libs to java libs, which you noticed and liked even though you weren't in that thread... I don't think I could follow as many threads on this forum as you do, @pturmel 🙂

---

<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:** [August 24, 2023, 3:02pm UTC](https://forum.inductiveautomation.com/t/fileupload-component-trying-to-get-the-byte-string-in-base64-format/78282/6 "2023-08-24T15:02:51Z")

</div>

> [@justin.brzozoski](#):
>
> don't think I could follow as many threads on this forum as you do

I'm sure you could--this forum's underlying software (Discourse) makes it easy. I just set all categories to "watching", so the notification system keeps track of what I haven't seen. Then, whenever I take a break from coding (several times a day, typically), I just run through the topics that Discourse points out.
