Saving and reading image from file problem

Hi everyone,
I am quite new to node-red so I guess I am doing some beginners mistake.

I use the image-tools library to view the data which is going to be saved and applied additionally a watch to the same file which is rewritten each 10s.
The readout from the webcam works fine before saving everything seems ok, the file-out node does also fine as i see the file re-written properly in the filesystem.

But my problem is, that for some reason I cant read the file properly.
The image-viewer node for the watched file gives me: "Error: Could not find MIME for Buffer " .

Maybe someone is able to give me some advice on the problem - I guessed its about the encoding how the file is saved but whatever I change in the file-out node.

btw. The file is stored in the users home dir which should not be the problem.

Thanks a lot for any help,
cheers Christian

While a 'picture is worth a thousand words', in this case exporting your flow ad pasting it into a reply would be even better.

Hi, yea i thought about that too :wink:
Here we go:

[
    {
        "id": "9702a14d.73243",
        "type": "file",
        "z": "c7da62cf.1df24",
        "name": "save image to folder",
        "filename": "/home/christian/birdbox/latest.jpg",
        "appendNewline": false,
        "createDir": true,
        "overwriteFile": "true",
        "encoding": "base64",
        "x": 820,
        "y": 320,
        "wires": [
            [
                "2ddc2464.54ebec",
                "60a7ffc9.181c3"
            ]
        ]
    },
    {
        "id": "ac8e6950.03c7e8",
        "type": "comment",
        "z": "c7da62cf.1df24",
        "name": "Saving image",
        "info": "",
        "x": 277,
        "y": 269,
        "wires": [ ]
    },
    {
        "id": "2ddc2464.54ebec",
        "type": "debug",
        "z": "c7da62cf.1df24",
        "name": "file",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 1030,
        "y": 320,
        "wires": []
    },
    {
        "id": "2b37d903.c98f96",
        "type": "ui_button",
        "z": "c7da62cf.1df24",
        "name": "",
        "group": "ba799367.ad2e3",
        "order": 5,
        "width": "3",
        "height": "1",
        "passthru": false,
        "label": "Take Picture",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "icon": "",
        "payload": "",
        "payloadType": "str",
        "topic": "",
        "x": 90,
        "y": 320,
        "wires": [
            [
                "9cb14399.fea1"
            ]
        ]
    },
    {
        "id": "2b9b3b3.a7944c4",
        "type": "comment",
        "z": "c7da62cf.1df24",
        "name": "Latest image",
        "info": "This template node has the HTML code to display\nthe latest image from the motion program.\n",
        "x": 270,
        "y": 480,
        "wires": []
    },
    {
        "id": "8d55914a.2a88e",
        "type": "ui_template",
        "z": "c7da62cf.1df24",
        "group": "8a23a84e.52b3f8",
        "name": "Last Image",
        "order": 2,
        "width": "7",
        "height": "7",
        "format": "<!--<img name=\"main\" id=\"main\" border=\"0\" width=\"480\" height=\"460\" src=\"../webcam/{{msg.stamp}}.jpg\"> -->\n<img width=\"480\" height\"460\" src=\"/home/christian/birdbox/latest.jpg\" />\n\n<br>\nLAST IMAGE <h3>\n   <i class=\"fa fa-download\" aria-hidden=\"true\"></i>\n   <a href=\"../gif/{{ msg.payload }}.gif\" download=\"time-shift.gif\">Download This GIF </a>|\n   <i class=\"fa fa-refresh\" aria-hidden=\"true\"></i>\n   <a href=\"../ui\"> Reload Page</a>\n      \n</h3>",
        "storeOutMessages": true,
        "fwdInMessages": false,
        "resendOnRefresh": false,
        "templateScope": "local",
        "x": 470,
        "y": 540,
        "wires": [
            [
                "885283b2.6709f"
            ]
        ]
    },
    {
        "id": "885283b2.6709f",
        "type": "debug",
        "z": "c7da62cf.1df24",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 650,
        "y": 540,
        "wires": []
    },
    {
        "id": "25e8662a.c1f86a",
        "type": "debug",
        "z": "c7da62cf.1df24",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 350,
        "y": 360,
        "wires": []
    },
    {
        "id": "aeb08572.e35c88",
        "type": "configurable interval",
        "z": "c7da62cf.1df24",
        "name": "configurable interval",
        "interval": "10",
        "onstart": true,
        "do_enable": true,
        "msg": "capture photo",
        "showstatus": true,
        "unit": "seconds",
        "statusformat": "YYYY-MM-D HH:mm:ss",
        "x": 120,
        "y": 400,
        "wires": [
            [
                "25e8662a.c1f86a",
                "9cb14399.fea1"
            ]
        ]
    },
    {
        "id": "9cb14399.fea1",
        "type": "function",
        "z": "c7da62cf.1df24",
        "name": "set payload and headers",
        "func": "msg.headers = {};\n//msg.headers['Accept-Encoding'] = 'gzip';\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 310,
        "y": 320,
        "wires": [
            [
                "f5c76e11.d815d"
            ]
        ]
    },
    {
        "id": "f5c76e11.d815d",
        "type": "jimp-image",
        "z": "c7da62cf.1df24",
        "name": "single capture",
        "data": "http://192.168.22.7/capture",
        "dataType": "str",
        "ret": "img",
        "parameter1": "",
        "parameter1Type": "msg",
        "parameter2": "",
        "parameter2Type": "msg",
        "parameter3": "",
        "parameter3Type": "msg",
        "parameter4": "",
        "parameter4Type": "msg",
        "parameter5": "",
        "parameter5Type": "msg",
        "parameter6": "",
        "parameter6Type": "msg",
        "parameter7": "",
        "parameter7Type": "msg",
        "parameter8": "",
        "parameter8Type": "msg",
        "sendProperty": "payload",
        "parameterCount": 0,
        "jimpFunction": "none",
        "selectedJimpFunction": {
            "name": "none",
            "fn": "none",
            "description": "Just loads the image.",
            "parameters": []
        },
        "x": 560,
        "y": 320,
        "wires": [
            [
                "9702a14d.73243"
            ]
        ]
    },
    {
        "id": "3be63024.85497",
        "type": "watch",
        "z": "c7da62cf.1df24",
        "name": "latest.jpeg",
        "files": "/home/christian/birdbox/latest.jpg",
        "recursive": "",
        "x": 260,
        "y": 540,
        "wires": [
            [
                "8d55914a.2a88e",
                "31ff0f0b.951cd"
            ]
        ]
    },
    {
        "id": "31ff0f0b.951cd",
        "type": "image viewer",
        "z": "c7da62cf.1df24",
        "name": "",
        "width": "160",
        "data": "payload",
        "dataType": "msg",
        "x": 790,
        "y": 480,
        "wires": [
            []
        ]
    },
    {
        "id": "60a7ffc9.181c3",
        "type": "image viewer",
        "z": "c7da62cf.1df24",
        "name": "",
        "width": "160",
        "data": "payload",
        "dataType": "msg",
        "x": 1030,
        "y": 380,
        "wires": [
            []
        ]
    },
    {
        "id": "ba799367.ad2e3",
        "type": "ui_group",
        "name": "Group 2",
        "tab": "21cd106a.5f882",
        "order": 2,
        "disp": true,
        "width": 6
    },
    {
        "id": "8a23a84e.52b3f8",
        "type": "ui_group",
        "z": "",
        "name": "Group 1",
        "tab": "21cd106a.5f882",
        "order": 1,
        "disp": false,
        "width": "15",
        "collapse": false
    },
    {
        "id": "21cd106a.5f882",
        "type": "ui_tab",
        "z": "",
        "name": "Webcam",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

Can you view the file ok outside of node red?

If you can then it may be that in node-red you are trying to view the file before it is fully written. The Watch node triggers as soon as the first buffer is written, and may trigger multiple times as the file gets written to. You should be able to solve that by inserting after the Watch node a Trigger node configured to Send Nothing then Wait 2 seconds then Send Original Message and with Extend Delay set. That will delay the view till two seconds after the last output from the Watch node.

If it isn't that then it may be that you have mis-configured the node writing the file.

I tried to copy the picture, because this machine has no GUI, so after doing so I checked and ineed the written file was scrambled - and had some problems with the file header.

Since I saw in the first viewer that the image is there - I thought its written properly but indeed it wasn't.

That's it - for a reason I do not understand (yet), I had to change the output of the image capture node to 'buffer' - which may be more raw data then if set to 'image'.
The triggering of the watch does not seem to cause a problem now.

Thanks for the hints,
cheers Christian

1 Like

The file is scrambled because you are trying to write the jimp object instead of the the image buffer

alternatively, just use the image node function "write"

image

1 Like

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