# Undefined when trying to save gmail attachment

**URL:** <https://discourse.nodered.org/t/undefined-when-trying-to-save-gmail-attachment/8642>\
**Category:** General\
**Created:** [5 March 2019 19:25 UTC](https://discourse.nodered.org/t/undefined-when-trying-to-save-gmail-attachment/8642 "2019-03-05T19:25:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![NRdiscrs9393](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nrdiscrs9393/32/726_2.png) [@NRdiscrs9393](https://discourse.nodered.org/u/NRdiscrs9393)\
**Post date:** [5 March 2019 19:25 UTC](https://discourse.nodered.org/t/undefined-when-trying-to-save-gmail-attachment/8642/1 "2019-03-05T19:25:53Z")

</div>

Hello,

The Store Attachment function in the attached flow is not defining the filename while trying to save a gmail attachment. The result of the flow creates filename: "../../mnt/BreachMedia/undefined" and will not store the "Sterile Door.jpg" into the "./../mnt/BreachMedia/". I can confirm with another flow that I can indeed store into the directory shown. Any guidance would b helpful.

![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7b9d129a4d23fcbcab68412439f77aaf4ad58e7a.png)

Here are the debug logs

```auto

3/5/2019, 1:14:56 PMnode: Filter
Sterile Exit Wrong Way : msg : Object
object
payload: "Sterile Exit Wrong Way↵01:14 PM, 2019-03-05"
topic: "Sterile Exit Wrong Way"
date: "2019-03-05T19:14:44.000Z"
header: object
from: "exacqvision-cll@astin.us"
attachments: array[1]
0: object
contentType: "image/jpeg"
transferEncoding: "base64"
contentDisposition: "attachment"
fileName: "Sterile Door.jpg"
generatedFileName: "Sterile Door.jpg"
contentId: "ef17b59d012ac560aaea2101bb3f267a@mailparser"
checksum: "b3a3949dd1073b7643b01fbc48c73a1d"
length: 172037
content: buffer[172037]
_msgid: "4812fa08.3c5b04"
_event: "node:409e8e9e.a454e"

3/5/2019, 1:14:56 PMnode: Store
Sterile Exit Wrong Way : msg : Object
object
topic: "Sterile Exit Wrong Way"
date: "2019-03-05T19:14:44.000Z"
header: object
from: "exacqvision-cll@astin.us"
attachments: array[1]
0: object
contentType: "image/jpeg"
transferEncoding: "base64"
contentDisposition: "attachment"
fileName: "Sterile Door.jpg"
generatedFileName: "Sterile Door.jpg"
contentId: "ef17b59d012ac560aaea2101bb3f267a@mailparser"
checksum: "b3a3949dd1073b7643b01fbc48c73a1d"
length: 172037
content: buffer[172037]
_msgid: "4812fa08.3c5b04"
_event: "node:409e8e9e.a454e"
parts: object
filename: "../../mnt/BreachMedia/undefined"

```

Here is the flow

```auto
[
    {
        "id": "42b14509.52d85c",
        "type": "function",
        "z": "cd3efe20.4f582",
        "name": "Store Attachment",
        "func": "msg.filename = \"../../mnt/BreachMedia/\"+msg.payload.fileName;\nmsg.payload = msg.payload.content;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 350,
        "y": 1220,
        "wires": [
            [
                "9cdee59a.46a8e8",
                "faf0c732.0b2898"
            ]
        ]
    },
    {
        "id": "9cdee59a.46a8e8",
        "type": "file",
        "z": "cd3efe20.4f582",
        "name": "Write attachement",
        "filename": "",
        "appendNewline": false,
        "createDir": true,
        "overwriteFile": "true",
        "x": 352.99998474121094,
        "y": 1263.9999551773071,
        "wires": [
            []
        ]
    },
    {
        "id": "ee963462.056188",
        "type": "split",
        "z": "cd3efe20.4f582",
        "name": "",
        "splt": "",
        "x": 310.99999618530273,
        "y": 1181.9999933242798,
        "wires": [
            [
                "42b14509.52d85c",
                "d50fb267.7ce93"
            ]
        ]
    },
    {
        "id": "dbf67f61.c6304",
        "type": "debug",
        "z": "cd3efe20.4f582",
        "name": "Filter",
        "active": true,
        "console": "false",
        "complete": "true",
        "x": 570,
        "y": 1140,
        "wires": []
    },
    {
        "id": "d50fb267.7ce93",
        "type": "debug",
        "z": "cd3efe20.4f582",
        "name": "Split",
        "active": true,
        "console": "false",
        "complete": "true",
        "x": 570,
        "y": 1180,
        "wires": []
    },
    {
        "id": "faf0c732.0b2898",
        "type": "debug",
        "z": "cd3efe20.4f582",
        "name": "Store",
        "active": true,
        "console": "false",
        "complete": "true",
        "x": 570,
        "y": 1220,
        "wires": []
    },
    {
        "id": "ede31fd2.bcaee",
        "type": "switch",
        "z": "cd3efe20.4f582",
        "name": "exacqvision-cll",
        "property": "from",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "exacqvision-cll",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "outputs": 1,
        "x": 280,
        "y": 1140,
        "wires": [
            [
                "ee963462.056188",
                "dbf67f61.c6304"
            ]
        ]
    }
]

```

---

<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:** [5 March 2019 20:16 UTC](https://discourse.nodered.org/t/undefined-when-trying-to-save-gmail-attachment/8642/2 "2019-03-05T20:16:45Z")

</div>

I suggest using the full path to the file, it is sometimes difficult to be certain what the current directory is.

---

<div class="post-metadata">

**Author:** ![NRdiscrs9393](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nrdiscrs9393/32/726_2.png) [@NRdiscrs9393](https://discourse.nodered.org/u/NRdiscrs9393)\
**Post date:** [5 March 2019 20:20 UTC](https://discourse.nodered.org/t/undefined-when-trying-to-save-gmail-attachment/8642/3 "2019-03-05T20:20:41Z")

</div>

Thanks and I believe the error is in the function as it cannot resolve the filename. Any ideas for the function?

```auto
msg.filename = "../../mnt/BreachMedia/"+msg.payload.fileName;
msg.payload = msg.payload.content;
return msg;

```

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [5 March 2019 21:02 UTC](https://discourse.nodered.org/t/undefined-when-trying-to-save-gmail-attachment/8642/4 "2019-03-05T21:02:53Z")

</div>

So look at the debug output to check the path is correct (it doesn't look as if it is from your unformatted debug output as the email can have more than one attachment filename etc will be in an array)

This page describes how you can use the tooltips to check in a debug panel  
[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![NRdiscrs9393](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nrdiscrs9393/32/726_2.png) [@NRdiscrs9393](https://discourse.nodered.org/u/NRdiscrs9393)\
**Post date:** [5 March 2019 22:31 UTC](https://discourse.nodered.org/t/undefined-when-trying-to-save-gmail-attachment/8642/5 "2019-03-05T22:31:31Z")

</div>

I can confirm the path is correct by statically naming the file "../../mnt/BreachMedia/Sterile Door.txt" in the file node and performing a timestamp injection. The issue seems to be with the extracting the attachment from the **Gmail** message. I have tested this flow with a local **PostfFix** server and have no problems storing the attachments.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [5 March 2019 22:34 UTC](https://discourse.nodered.org/t/undefined-when-trying-to-save-gmail-attachment/8642/6 "2019-03-05T22:34:19Z")

</div>

msg.payload.filename is wrong

Your debug shows this. Read the page I linked to, use the debug panel to find the correct (hint it’s in an array)
