# Msg.payload always give me false?

**URL:** <https://discourse.nodered.org/t/msg-payload-always-give-me-false/80315>\
**Category:** General\
**Created:** [4 August 2023 09:23 UTC](https://discourse.nodered.org/t/msg-payload-always-give-me-false/80315 "2023-08-04T09:23:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![54jinyistudio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/54jinyistudio/32/81424_2.png) [@54jinyistudio](https://discourse.nodered.org/u/54jinyistudio)\
**Post date:** [4 August 2023 09:23 UTC](https://discourse.nodered.org/t/msg-payload-always-give-me-false/80315/1 "2023-08-04T09:23:15Z")

</div>

I write following code in a "function node". I can download image file and write to file but msg.payload always is false. Why ? 🙄

```auto
const axios = global.get('axios');
const fs = global.get('fs');
var msg={"payload":false};

async function downloadImage(url, filename) {
    const response = await axios.get(url, { responseType: 'arraybuffer' });

    fs.writeFile(filename, response.data, (err) => {
        if (err) {
            
        }
        else {            
            msg.payload = true;        
        }        
    });
}

downloadImage('https://api.telegram.org/file/bot1776047125:AAGFueEEbGMejFuplD4zsUjB5Eu3BnzvMTo/photos/file_24.jpg', 'd:/temp/image.jpg');
return msg;

```

---

<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:** [4 August 2023 10:17 UTC](https://discourse.nodered.org/t/msg-payload-always-give-me-false/80315/2 "2023-08-04T10:17:16Z")

</div>

Hard to say but there are many things your script need to be reliable. For example, you dont check the response code. You dont do anything with the `err` object

However, since we are in Node-RED (low-code/no-code) I am wondering why you are using axios?

Why not simply do this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0ad283ce4c599a01a2d66929eaa592b064164f79.png)

And if it is because you want a means of resuing (not duplicating flows elements) then use a subflow or subroutine

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/2/e2f3e014baab30166431ab8925fc19374ec1b21f.png)

---

<div class="post-metadata">

**Author:** ![54jinyistudio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/54jinyistudio/32/81424_2.png) [@54jinyistudio](https://discourse.nodered.org/u/54jinyistudio)\
**Post date:** [4 August 2023 20:15 UTC](https://discourse.nodered.org/t/msg-payload-always-give-me-false/80315/3 "2023-08-04T20:15:25Z")

</div>

Can you share your flow json to me ? 👍

---

<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:** [4 August 2023 20:20 UTC](https://discourse.nodered.org/t/msg-payload-always-give-me-false/80315/4 "2023-08-04T20:20:35Z")

</div>

I never deployed it / didn't keep it.

Not difficult to create though - give it a go.

---

<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:** [3 October 2023 20:21 UTC](https://discourse.nodered.org/t/msg-payload-always-give-me-false/80315/5 "2023-10-03T20:21:02Z")

</div>

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