# Mqtt to save a file

**URL:** <https://discourse.nodered.org/t/mqtt-to-save-a-file/11495>\
**Category:** General\
**Created:** [24 May 2019 05:59 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495 "2019-05-24T05:59:00Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![oli.nodered](https://avatars.discourse-cdn.com/v4/letter/o/e9bcb4/32.png) [@oli.nodered](https://discourse.nodered.org/u/oli.nodered)\
**Post date:** [24 May 2019 05:59 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/1 "2019-05-24T05:59:00Z")

</div>

Bonjour  
i use mqtt to download an image to an another node red application.  
I can display this file/image on my dashboard, but i can't save the file on the disk  
can you help me ?  
Merci  
Olivier

---

<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:** [24 May 2019 06:01 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/2 "2019-05-24T06:01:08Z")

</div>

Have you tried sending the image data to a file node?

---

<div class="post-metadata">

**Author:** ![machadotiago](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/machadotiago/32/23776_2.png) [@machadotiago](https://discourse.nodered.org/u/machadotiago)\
**Post date:** [25 May 2019 19:13 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/3 "2019-05-25T19:13:07Z")

</div>

Maybe you could try posting your flow here?

---

<div class="post-metadata">

**Author:** ![oli.nodered](https://avatars.discourse-cdn.com/v4/letter/o/e9bcb4/32.png) [@oli.nodered](https://discourse.nodered.org/u/oli.nodered)\
**Post date:** [27 May 2019 07:02 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/4 "2019-05-27T07:02:21Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/60e201fc2ada06ec84801291a292979279cde400.png)  
Bonjour  
this is my flow  
i want just to save the file on my disk  
Merci  
Olivier

---

<div class="post-metadata">

**Author:** ![oli.nodered](https://avatars.discourse-cdn.com/v4/letter/o/e9bcb4/32.png) [@oli.nodered](https://discourse.nodered.org/u/oli.nodered)\
**Post date:** [27 May 2019 07:03 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/5 "2019-05-27T07:03:17Z")

</div>

no, i want to use the MQTT protocol.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 May 2019 07:39 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/6 "2019-05-27T07:39:57Z")

</div>

Can you explain in more detail what you mean? MQTT is not a protocol for writing to disk. Unless you mean that you want the MQTT topic containing the image to be retained by the MQTT broker. In which case you can set the Retained flag when you publish it to MQTT.

---

<div class="post-metadata">

**Author:** ![oli.nodered](https://avatars.discourse-cdn.com/v4/letter/o/e9bcb4/32.png) [@oli.nodered](https://discourse.nodered.org/u/oli.nodered)\
**Post date:** [27 May 2019 09:07 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/7 "2019-05-27T09:07:12Z")

</div>

i know mqtt is not a protocol for writting to disk. i just use this protocol to upload/dowload my image.  
When i receive my data with the mqtt protocol, i just transform it to display my image into the dashboard.  
that it is ok.  
now, i just want save the file, not only display it on my dashbord. this is my problem.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 May 2019 09:17 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/8 "2019-05-27T09:17:19Z")

</div>

Then use a File Out node to write it to the file as well as sending it to your template as @Steve-Mcl suggested.

---

<div class="post-metadata">

**Author:** ![oli.nodered](https://avatars.discourse-cdn.com/v4/letter/o/e9bcb4/32.png) [@oli.nodered](https://discourse.nodered.org/u/oli.nodered)\
**Post date:** [27 May 2019 12:54 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/9 "2019-05-27T12:54:35Z")

</div>

Colin, i do that but i had an error when i trie to open the file with a file editor.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 May 2019 13:03 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/10 "2019-05-27T13:03:24Z")

</div>

What sort of error? Wouldn't you be better to open it with an image viewer?

---

<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:** [27 May 2019 16:33 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/11 "2019-05-27T16:33:11Z")

</div>

Where is the file node? after the base64? If so, that is not gonna be valid image data.  
Put the file node immediately after the mqtt node & try again. Additionally, set the filename to a location you are sure can be written. If it errors, post a screen shot. If you get an error opening the image in an image viewer, screen shot the error.

---

<div class="post-metadata">

**Author:** ![oli.nodered](https://avatars.discourse-cdn.com/v4/letter/o/e9bcb4/32.png) [@oli.nodered](https://discourse.nodered.org/u/oli.nodered)\
**Post date:** [29 May 2019 06:33 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/12 "2019-05-29T06:33:03Z")

</div>

Bonjour  
it is ok now. i just put the node behind the mqtt receiver and it is ok

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0d0de31aa00aa10610f30be8fe5bd54a555ed29f.png)  
just a remark, if i save the file with .jpeg, i have got a file with 239 ko and if i change the extension file with .JPEG have got a file with 716 ko.But i can open the both files, so it is ok for me now. I don't now why because i did that before... may be an update.  
Thanks for your help... and sorry for my english 🙂

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 May 2019 07:57 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/13 "2019-05-29T07:57:41Z")

</div>

Are you saying that in the flow you show, where you send the same message to two File nodes, that the two files end up with different lengths even though everything in the File nodes is the same except the name? That seems very surprising to me. Make sure you have not set Append to File in one of them.  
If you are convinced this is happening export the flow and post it here.

---

<div class="post-metadata">

**Author:** ![oli.nodered](https://avatars.discourse-cdn.com/v4/letter/o/e9bcb4/32.png) [@oli.nodered](https://discourse.nodered.org/u/oli.nodered)\
**Post date:** [29 May 2019 09:10 UTC](https://discourse.nodered.org/t/mqtt-to-save-a-file/11495/14 "2019-05-29T09:10:41Z")

</div>

Colin,  
i have set Append, i set Owerite, and now i have got same result.🙂  
Merci  
Olivier
