# Looking for guidance to add a functional "delete" link to delete file(s) in a folder

**URL:** <https://discourse.nodered.org/t/looking-for-guidance-to-add-a-functional-delete-link-to-delete-file-s-in-a-folder/61854>\
**Category:** General\
**Tags:** http-request\
**Created:** [27 April 2022 08:18 UTC](https://discourse.nodered.org/t/looking-for-guidance-to-add-a-functional-delete-link-to-delete-file-s-in-a-folder/61854 "2022-04-27T08:18:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zany](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zany](https://discourse.nodered.org/u/zany)\
**Post date:** [27 April 2022 08:18 UTC](https://discourse.nodered.org/t/looking-for-guidance-to-add-a-functional-delete-link-to-delete-file-s-in-a-folder/61854/1 "2022-04-27T08:18:15Z")

</div>

Continuing the discussion from [Unable to download files from the browser](https://discourse.nodered.org/t/unable-to-download-files-from-the-browser/51314/6):

Hi everyone, i'm a newbiew to NodeRed and came across this post which is able to create a list from a folder and download link. it works great!

had tried to understand the codes and been playing around with it, however still unable to let the "delete" link to be functional.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/8/68a42391c849af2b4e0f41889fe1b52ac6df4389.png)

```auto
<table>
    <th>Files found</th>
    
    {{#files}}
     <tr>
        <td> {{.}} </td>
        <td> <a href="/files/{{{.}}}">download</a>
        <td>
        <td> <a href="/delete/{{{.}}}">delete</a>
        <td>
    </tr>
    {{/files}}
</table>

```

did as above but lost of direction what can i do next to move on. had lots of trial and error to have more understanding but however what i get most of the time was as below. on the positive side was the filename returned (although with error) was the name intended to be deleted 😂

"Cannot GET /delete/20220411.csv"

Thanks in advance! 😊

---

<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:** [27 April 2022 08:21 UTC](https://discourse.nodered.org/t/looking-for-guidance-to-add-a-functional-delete-link-to-delete-file-s-in-a-folder/61854/2 "2022-04-27T08:21:29Z")

</div>

> [@zany](#):
>
> "Cannot GET /delete/20220411.csv"

Did you add an endpoint for `/delete` & hook that up to the necessary logic to perform the delete?

---

<div class="post-metadata">

**Author:** ![zany](https://avatars.discourse-cdn.com/v4/letter/z/d26b3c/32.png) [@zany](https://discourse.nodered.org/u/zany)\
**Post date:** [27 April 2022 08:32 UTC](https://discourse.nodered.org/t/looking-for-guidance-to-add-a-functional-delete-link-to-delete-file-s-in-a-folder/61854/3 "2022-04-27T08:32:57Z")

</div>

Hi Steve! thanks for the prompt response

```auto
[
    {
        "id": "0829d2663c2cbbca",
        "type": "function",
        "z": "e582dbe7569c9c4e",
        "name": "Set base path",
        "func": "//restrict to c:\\temp\\\nvar basePath = flow.get(\"basePath\");\nvar filename = msg.req.params.fn;\n\n\nif(filename.includes(\"..\\\\\")){\n msg.payload = \"Illegal file path\";\n msg.statusCode = 405;//not allowed\n return [null, msg];//fire output 2\n} else if(filename.includes(\"../\")){\n msg.payload = \"Illegal file path\";\n msg.statusCode = 405;//not allowed\n return [null, msg];//fire output 2\n} \n//TODO: add more checks\n\nmsg.filename = basePath + filename;\nreturn [msg, null];//fire output 1\n\n\n",
        "outputs": 2,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1100,
        "y": 660,
        "wires": [
            [
                "11ed99d831349ff6",
                "6a8dcab2d3b975be"
            ],
            [
                "b2f7eb8cfcba09d8"
            ]
        ]
    },
    {
        "id": "b2f7eb8cfcba09d8",
        "type": "http response",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 1410,
        "y": 720,
        "wires": []
    },
    {
        "id": "11ed99d831349ff6",
        "type": "file in",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "filename": "",
        "format": "",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "allProps": false,
        "x": 1320,
        "y": 660,
        "wires": [
            [
                "b2f7eb8cfcba09d8"
            ]
        ]
    },
    {
        "id": "740a73135bb53bb7",
        "type": "catch",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "scope": null,
        "uncaught": false,
        "x": 880,
        "y": 720,
        "wires": [
            [
                "df88955353671807",
                "bcbc4da718e60095"
            ]
        ]
    },
    {
        "id": "df88955353671807",
        "type": "function",
        "z": "e582dbe7569c9c4e",
        "name": "Set 404",
        "func": "msg.payload = msg.error;\nmsg.statusCode = 404;//resource not found\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1200,
        "y": 720,
        "wires": [
            [
                "b2f7eb8cfcba09d8"
            ]
        ]
    },
    {
        "id": "bcbc4da718e60095",
        "type": "debug",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "x": 1050,
        "y": 700,
        "wires": []
    },
    {
        "id": "5ffcf157d5c4e561",
        "type": "ui_template",
        "z": "e582dbe7569c9c4e",
        "group": "dfb4a60f.d788f8",
        "name": "ui_temlplate - present download links on dashboard",
        "order": 1,
        "width": "7",
        "height": "8",
        "format": "<div ng-bind-html=\"msg.payload\"></div>",
        "storeOutMessages": true,
        "fwdInMessages": true,
        "resendOnRefresh": false,
        "templateScope": "local",
        "className": "",
        "x": 1310,
        "y": 800,
        "wires": [
            []
        ]
    },
    {
        "id": "5429470c045925c9",
        "type": "comment",
        "z": "e582dbe7569c9c4e",
        "name": "Create http endpoint <nodered>/files/xxx where xxx is the file name to download",
        "info": "",
        "x": 1040,
        "y": 620,
        "wires": []
    },
    {
        "id": "f51f310fa49f72e3",
        "type": "http in",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "url": "/files/:fn",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 890,
        "y": 660,
        "wires": [
            [
                "0829d2663c2cbbca",
                "86e4b4968b4f185b"
            ]
        ]
    },
    {
        "id": "cede760ddd3693af",
        "type": "inject",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "/home/orangepi/datalog/",
        "payloadType": "str",
        "x": 890,
        "y": 580,
        "wires": [
            [
                "db7cbbbe1ea13b1a"
            ]
        ]
    },
    {
        "id": "db7cbbbe1ea13b1a",
        "type": "change",
        "z": "e582dbe7569c9c4e",
        "name": "store flow.basePath",
        "rules": [
            {
                "t": "set",
                "p": "basePath",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1130,
        "y": 580,
        "wires": [
            []
        ]
    },
    {
        "id": "80825c1d79c2b94c",
        "type": "ui_ui_control",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "events": "all",
        "x": 840,
        "y": 800,
        "wires": [
            [
                "c9c91dfef1e3aec8"
            ]
        ]
    },
    {
        "id": "0e39a125e27ab6c6",
        "type": "comment",
        "z": "e582dbe7569c9c4e",
        "name": "Setup basePath",
        "info": "",
        "x": 840,
        "y": 540,
        "wires": []
    },
    {
        "id": "1e4aca0214eb0cc6",
        "type": "comment",
        "z": "e582dbe7569c9c4e",
        "name": "Get files in basePath and generate table",
        "info": "",
        "x": 910,
        "y": 760,
        "wires": []
    },
    {
        "id": "ae8f44c9ddf01a9c",
        "type": "inject",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 860,
        "y": 840,
        "wires": [
            [
                "c9c91dfef1e3aec8"
            ]
        ]
    },
    {
        "id": "d680804e3853c21b",
        "type": "template",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "<table>\n <th>Files</th>\n \n {{#files}}\n <tr>\n <td> {{.}} </td>\n <td> <a href=\"/files/{{{.}}}\">download</a>\n <td>\n <td> <a href=\"/delete/{{{.}}}\">delete</a>\n <td>\n </tr>\n {{/files}}\n</table>",
        "output": "str",
        "x": 1040,
        "y": 840,
        "wires": [
            [
                "5ffcf157d5c4e561"
            ]
        ]
    },
    {
        "id": "c9c91dfef1e3aec8",
        "type": "fs-ops-dir",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "path": "basePath",
        "pathType": "flow",
        "filter": "*.csv",
        "filterType": "str",
        "dir": "files",
        "dirType": "msg",
        "x": 1000,
        "y": 800,
        "wires": [
            [
                "d680804e3853c21b"
            ]
        ]
    },
    {
        "id": "86e4b4968b4f185b",
        "type": "debug",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1130,
        "y": 920,
        "wires": []
    },
    {
        "id": "b20368ff6c391b0a",
        "type": "http in",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "url": "/delete/:fn",
        "method": "delete",
        "upload": false,
        "swaggerDoc": "",
        "x": 870,
        "y": 960,
        "wires": [
            [
                "0829d2663c2cbbca"
            ]
        ]
    },
    {
        "id": "6a8dcab2d3b975be",
        "type": "fs-ops-delete",
        "z": "e582dbe7569c9c4e",
        "name": "",
        "path": "",
        "pathType": "str",
        "filename": "*",
        "filenameType": "msg",
        "x": 1330,
        "y": 940,
        "wires": [
            [
                "b2f7eb8cfcba09d8"
            ]
        ]
    },
    {
        "id": "dfb4a60f.d788f8",
        "type": "ui_group",
        "name": "Select files to download",
        "tab": "f2e6c77a41682d29",
        "order": 2,
        "disp": true,
        "width": "7",
        "collapse": false,
        "className": ""
    },
    {
        "id": "f2e6c77a41682d29",
        "type": "ui_tab",
        "name": "Page 2: Data",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]

```

i had edited the template and simply added the http request node as above. i'm not sure if i missed out anything else.

added nodes are

1. another http request node with delete
2. fs-ops-delete node

do you mind to have a look at it?

thanks in advance!!

---

<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:** [26 June 2022 08:33 UTC](https://discourse.nodered.org/t/looking-for-guidance-to-add-a-functional-delete-link-to-delete-file-s-in-a-folder/61854/4 "2022-06-26T08:33:58Z")

</div>

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