# Store the empty msg.payload inside the file

**URL:** <https://discourse.nodered.org/t/store-the-empty-msg-payload-inside-the-file/69477>\
**Category:** General\
**Created:** [24 October 2022 09:45 UTC](https://discourse.nodered.org/t/store-the-empty-msg-payload-inside-the-file/69477 "2022-10-24T09:45:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giacomo23](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@Giacomo23](https://discourse.nodered.org/u/Giacomo23)\
**Post date:** [24 October 2022 09:45 UTC](https://discourse.nodered.org/t/store-the-empty-msg-payload-inside-the-file/69477/1 "2022-10-24T09:45:53Z")

</div>

hello everyone, I have a problem I have to store files with the name that is entered in a textbox, and I succeeded the only problem I have is that all the msg.payload is saved inside the file when in actually I need it to be empty  
 ![0](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/774100cb1e145c52428bb0074e4772055e74aa1d.png)

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/77f543fc84e8b0461a79ee91a9ae16f03f7f26a2.png)  
 ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/751e93d9395137170b42a447745f6b74e67006ee.png)  
 ![3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/b/8b5d36e56f45a04b3ab5c75bd23af594412d705f.png)  
 ![4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/5313f2c432d94ccda508c78c270922982d479dc6.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [24 October 2022 09:59 UTC](https://discourse.nodered.org/t/store-the-empty-msg-payload-inside-the-file/69477/2 "2022-10-24T09:59:05Z")

</div>

```auto
let a = "/path/to/file/";
msg.file = a + msg.payload.file;
msg.payload = "";
return msg;

```

Then in the file node use `msg.file`, and uncheck add a newline to each payload.

---

<div class="post-metadata">

**Author:** ![Giacomo23](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@Giacomo23](https://discourse.nodered.org/u/Giacomo23)\
**Post date:** [24 October 2022 14:41 UTC](https://discourse.nodered.org/t/store-the-empty-msg-payload-inside-the-file/69477/3 "2022-10-24T14:41:06Z")

</div>

Perfect works very well thanks.  
another question if i can how do i make the variable  
global "msg.file" so that it can also be used in another flow or even on blocks that are not directly connected to each other

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [24 October 2022 14:53 UTC](https://discourse.nodered.org/t/store-the-empty-msg-payload-inside-the-file/69477/4 "2022-10-24T14:53:18Z")

</div>

You can global.set in the function before returning message.  
This is explained in docs  
[https://nodered.org/docs/user-guide/context](https://nodered.org/docs/user-guide/context)  
[https://nodered.org/docs/user-guide/writing-functions#storing-data](https://nodered.org/docs/user-guide/writing-functions#storing-data)

Or you can use a change node to set global.file to msg.file

---

<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:** [7 November 2022 14:53 UTC](https://discourse.nodered.org/t/store-the-empty-msg-payload-inside-the-file/69477/5 "2022-11-07T14:53:37Z")

</div>

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