# Base64 decode support

**URL:** <https://forum.getodk.org/t/base64-decode-support/40282>\
**Category:** Ideas\
**Created:** [February 1, 2023, 7:58pm UTC](https://forum.getodk.org/t/base64-decode-support/40282 "2023-02-01T19:58:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TobiasMcNulty](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/tobiasmcnulty/32/19773_2.png) [@TobiasMcNulty](https://forum.getodk.org/u/TobiasMcNulty)\
**Post date:** [February 1, 2023, 7:58pm UTC](https://forum.getodk.org/t/base64-decode-support/40282/1 "2023-02-01T19:58:50Z")

</div>

I am hoping to scan a QR code with the barcode scanner that is encoded via base64. I thought I found an XPath function `base64Decode` that might work, but I think that's possibly [only available as an extension](https://stackoverflow.com/questions/54989486/xpath-base64decode-not-working-in-wso2esb-4-8-1).

Short of creating a separate Android app to provide the scanning and decoding via an intent, are there other workaround that might allow for base64-decoding a value in ODK?

---

<div class="post-metadata">

**Author:** ![yanokwa](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/yanokwa/32/1695_2.png) [@yanokwa](https://forum.getodk.org/u/yanokwa)\
**Post date:** [February 1, 2023, 10:56pm UTC](https://forum.getodk.org/t/base64-decode-support/40282/2 "2023-02-01T22:56:56Z")

</div>

The function doesn't exist, but it's something we can add to the next release (rough ETA end of March) if it'd be helpful.

---

<div class="post-metadata">

**Author:** ![LN](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ln/32/1605_2.png) [@LN](https://forum.getodk.org/u/LN)\
**Post date:** [March 24, 2023, 4:15am UTC](https://forum.getodk.org/t/base64-decode-support/40282/3 "2023-03-24T04:15:40Z")

</div>

The `base64-decode` function is available in the [latest 2023.1 beta](https://forum.getodk.org/t/odk-collect-v2023-1-beta-select-traces-and-shapes-from-map-google-drive-deprecation-banner/40412) and should be released on Monday.

Documentation for the function is available [here](https://docs.getodk.org/form-operators-functions/#base64-decode).

---

<div class="post-metadata">

**Author:** ![TobiasMcNulty](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/tobiasmcnulty/32/19773_2.png) [@TobiasMcNulty](https://forum.getodk.org/u/TobiasMcNulty)\
**Post date:** [July 11, 2023, 7:50pm UTC](https://forum.getodk.org/t/base64-decode-support/40282/4 "2023-07-11T19:50:19Z")

</div>

We updated Central to 2023.3 but are seeing this error when attempting to upload a new draft with this function:

```auto
The XLSForm could not be converted: ODK Validate Errors:
>> Something broke the parser. See above for a hint.
Error evaluating field 'scan_decoded' (${item}[1]/scan_decoded[1]): The problem was located in Calculate expression for ${scan_decoded}
XPath evaluation: cannot handle function 'base64-decode'
Caused by: org.javarosa.xpath.XPathUnhandledException: The problem was located in Calculate expression for ${scan_decoded}
XPath evaluation: cannot handle function 'base64-decode'
	... 10 more

The following files failed validation:
foo.xml

Result: Invalid

```

---

<div class="post-metadata">

**Author:** ![TobiasMcNulty](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/tobiasmcnulty/32/19773_2.png) [@TobiasMcNulty](https://forum.getodk.org/u/TobiasMcNulty)\
**Post date:** [July 11, 2023, 8:16pm UTC](https://forum.getodk.org/t/base64-decode-support/40282/5 "2023-07-11T20:16:48Z")

</div>

We were able to work around this temporarily by changing `validate=True` to `validate=False` here: [https://github.com/getodk/pyxform-http/blob/37821e90554ffdc0b312b3840feaeff37fd8bfc0/app/main.py#L48](https://github.com/getodk/pyxform-http/blob/37821e90554ffdc0b312b3840feaeff37fd8bfc0/app/main.py#L48)

EDIT: See better fix below.

---

<div class="post-metadata">

**Author:** ![LN](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/ln/32/1605_2.png) [@LN](https://forum.getodk.org/u/LN)\
**Post date:** [July 11, 2023, 10:12pm UTC](https://forum.getodk.org/t/base64-decode-support/40282/6 "2023-07-11T22:12:42Z")

</div>

We need to update JavaRosa in Validate and update Validate in pyxform. Sorry about that.

I believe another option would be to change your form design to wrap the call in a conditional that relies on some value in the form being filled in. For example, if you want to decode the value from a field called `scanned`, you could use `if(${scanned}!='', base64-decode(${scanned}}, '')`.

This works because Validate doesn't perform any kind of analysis on the form definition, it just runs the form. In general this is not ideal behavior because it misses some validation. In this case it's something you can use to your advantage.

---

<div class="post-metadata">

**Author:** ![TobiasMcNulty](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/tobiasmcnulty/32/19773_2.png) [@TobiasMcNulty](https://forum.getodk.org/u/TobiasMcNulty)\
**Post date:** [July 12, 2023, 1:02am UTC](https://forum.getodk.org/t/base64-decode-support/40282/7 "2023-07-12T01:02:12Z")

</div>

Thanks for the quick response! That workaround does the trick, too. Many thanks. It's certainly nice to keep server-side validation enabled.
