# Text conversion Base64-\>utf-8

**URL:** <https://discourse.nodered.org/t/text-conversion-base64-utf-8/72251>\
**Category:** General\
**Created:** [15 December 2022 12:27 UTC](https://discourse.nodered.org/t/text-conversion-base64-utf-8/72251 "2022-12-15T12:27:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jen](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@Jen](https://discourse.nodered.org/u/Jen)\
**Post date:** [15 December 2022 12:27 UTC](https://discourse.nodered.org/t/text-conversion-base64-utf-8/72251/1 "2022-12-15T12:27:41Z")

</div>

Hello.  
I recive data in Base64 and need decode to utf-8.  
I used a converter, but it didn't help...  
Does anyone know how to do this?

```auto
[
    {
        "id": "15e0f3e34971d2cc",
        "type": "function",
        "z": "73a54536c2c8a28a",
        "name": "",
        "func": "const base64 = '0LPRgNGD0LTQvdGW';\nconst buff = Buffer.from(base64, 'base64');\nconst str = buff.toString('utf-8');\nconsole.log(str);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 380,
        "y": 3560,
        "wires": [
            [
                "80fd16e40118a0a7"
            ]
        ]
    },
    {
        "id": "80fd16e40118a0a7",
        "type": "debug",
        "z": "73a54536c2c8a28a",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 550,
        "y": 3560,
        "wires": []
    },
    {
        "id": "202e3eed2b1a9439",
        "type": "inject",
        "z": "73a54536c2c8a28a",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0LPRgNGD0LTQvdGW",
        "payloadType": "str",
        "x": 180,
        "y": 3560,
        "wires": [
            [
                "15e0f3e34971d2cc"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 December 2022 13:28 UTC](https://discourse.nodered.org/t/text-conversion-base64-utf-8/72251/2 "2022-12-15T13:28:06Z")

</div>

> [@Jen](#):
>
> `0LPRgNGD0LTQvdGW`

What do you get when you convert `0LPRgNGD0LTQvdGW` with your flow?  
What do you expect `0LPRgNGD0LTQvdGW` to be?

---

<div class="post-metadata">

**Author:** ![Jen](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@Jen](https://discourse.nodered.org/u/Jen)\
**Post date:** [15 December 2022 13:46 UTC](https://discourse.nodered.org/t/text-conversion-base64-utf-8/72251/3 "2022-12-15T13:46:23Z")

</div>

I get **0LPRgNGD0LTQvdGW**  
should be **грудні**  
This word is in Ukrainian

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 December 2022 13:52 UTC](https://discourse.nodered.org/t/text-conversion-base64-utf-8/72251/4 "2022-12-15T13:52:19Z")

</div>

Thats what I get.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/8/d86b387abedba28a9a478152fdee9cf3007584ef.png)

So it is something in your flow - specifically the function.

Try...

```auto
const base64 = '0LPRgNGD0LTQvdGW';
const buff = Buffer.from(base64, 'base64');
const str = buff.toString('utf-8');
msg.payload = str // <<< you missed this line
return msg;

```

---

<div class="post-metadata">

**Author:** ![Jen](https://avatars.discourse-cdn.com/v4/letter/j/ecae2f/32.png) [@Jen](https://discourse.nodered.org/u/Jen)\
**Post date:** [15 December 2022 14:16 UTC](https://discourse.nodered.org/t/text-conversion-base64-utf-8/72251/5 "2022-12-15T14:16:02Z")

</div>

> [@Steve-Mcl](#):
>
> ```auto
> const base64 = '0LPRgNGD0LTQvdGW';
> const buff = Buffer.from(base64, 'base64');
> const str = buff.toString('utf-8');
> msg.payload = str // <<< you missed this line
> return msg;
> 
> ```

thanks it worked

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 December 2022 14:16 UTC](https://discourse.nodered.org/t/text-conversion-base64-utf-8/72251/6 "2022-12-29T14:16:37Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
