Undefined when trying to save gmail attachment

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

Here are the debug logs


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

[
    {
        "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"
            ]
        ]
    }
]

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

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

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

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

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.

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)