# Saving a bas64 string to an image file

**URL:** <https://discourse.nodered.org/t/saving-a-bas64-string-to-an-image-file/65729>\
**Category:** Industrial\
**Created:** [28 July 2022 04:26 UTC](https://discourse.nodered.org/t/saving-a-bas64-string-to-an-image-file/65729 "2022-07-28T04:26:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [28 July 2022 04:26 UTC](https://discourse.nodered.org/t/saving-a-bas64-string-to-an-image-file/65729/1 "2022-07-28T04:26:18Z")

</div>

I am trying to save the image from a camera as an image file(.jpeg).

I currently ,I'm getting it as as base64 string. This was achieved by referring to the following link

> **[node-red-contrib-multipart-stream-decoder](https://flows.nodered.org/node/node-red-contrib-multipart-stream-decoder)**
>
> Node Red node for decoding multipart streams over http

I can use the following website to convert the file to an image

> **[Base64 to Image Decoder / Converter](https://codebeautify.org/base64-to-image-converter)**
>
> Best Online tool to converts base64 string into image. It's easy to use base64 image decoder which helps to decode picture and Download.

I was able to find the following forum thread that discusses it but Im not so clear on it  
[Saving images from URL to folder](https://discourse.nodered.org/t/saving-images-from-url-to-folder/21246).

I have included my nodes implementing that solution but I think Im missing something  
[flows (4).json](https://discourse.nodered.org/uploads/short-url/gIL4WzXYvNqsnd9J65iHwbUeGO8.json) (1.2 KB)

Please assist  
thank you

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [28 July 2022 05:26 UTC](https://discourse.nodered.org/t/saving-a-bas64-string-to-an-image-file/65729/2 "2022-07-28T05:26:50Z")

</div>

Hi @dinesh,  
It is not entirely clear to me how your setup works.

You show a link to my multipart decoder node, that gets a continious stream of images (as NodJs raw buffers) from your cam. But that node is not used in your flow...

You can encode an image (= buffer) to a base64 string, and convert it back to a buffer. That can be done with the same node.  
Bart

---

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [28 July 2022 06:19 UTC](https://discourse.nodered.org/t/saving-a-bas64-string-to-an-image-file/65729/3 "2022-07-28T06:19:26Z")

</div>

Hi,  
Actually I did used your nodes exactly to read my camera but the output was coming as base 64 string.  
But my intention is not to view the image and but save it.

So I created the nodes(which I uploaded) to read the base64 string and I was trying to find a way to convert it to an image file(.jpeg)..

---

<div class="post-metadata">

**Author:** ![dinesh](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@dinesh](https://discourse.nodered.org/u/dinesh)\
**Post date:** [28 July 2022 06:25 UTC](https://discourse.nodered.org/t/saving-a-bas64-string-to-an-image-file/65729/4 "2022-07-28T06:25:49Z")

</div>

> [@BartButenaers](#):
>
> You can encode an image (= buffer) to a base64 string, and convert it back to a buffer. That can be done with the same node.

Hi,  
I did not realise that the buffer itself can be saved as an image file. I tried this and it worked. I was trying to read the base64 string but it did not cross my mind to file output the buffer directly.  
My overall understanding is now a bit better

Thank you very much

---

<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:** [11 August 2022 06:26 UTC](https://discourse.nodered.org/t/saving-a-bas64-string-to-an-image-file/65729/5 "2022-08-11T06:26:21Z")

</div>

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