Receive a CSV file via HTTP In and Process

CSV Ingest into Flow via HTTP In

Have you ever needed to send a CSV file to your Node-RED instance? This file can go on to populate a shift schedule, product specifications, or some other configuration file that is used.

This flow takes in that CSV file to then be processed into a string that can then be used elsewhere.

Want a simple application to send files to Node-RED?

Simple script to send files to Node-RED:

import requests

def send_file(nodered_url, file_path):
    # Open the file in binary mode
    with open(file_path, 'rb') as file:
        files = {'file': (file.name, file, 'multipart/form-data')}
        response = requests.post(nodered_url, files=files)

    return response

# Update the ip address and port of your Node-RED instance
nodered_url = 'http://localhost:1880/fileupload'

# Update the location of your file
file_path = 'C:/Users/myUser/Downloads/shiftSchedule.csv'

response = send_file(nodered_url, file_path)
print(f"Response Status Code: {response.status_code}")
print(f"Response Body: {response.text}")
[{"id":"2cd668711b6a36b5","type":"group","z":"7dab245d6284333c","name":"Ingress CSV File and Format","style":{"label":true},"nodes":["691cb5678b88f2c6","38e3baae4603771c","d850ca57a7515064","447513976bbad321","53ca22d3e64ecf56","c0778a29661ad51d","8a186079cd832566"],"x":14,"y":19,"w":932,"h":122},{"id":"691cb5678b88f2c6","type":"http in","z":"7dab245d6284333c","g":"2cd668711b6a36b5","name":"","url":"/fileupload","method":"post","upload":true,"swaggerDoc":"","x":120,"y":60,"wires":[["d850ca57a7515064","53ca22d3e64ecf56"]]},{"id":"38e3baae4603771c","type":"debug","z":"7dab245d6284333c","g":"2cd668711b6a36b5","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":840,"y":60,"wires":[]},{"id":"d850ca57a7515064","type":"change","z":"7dab245d6284333c","g":"2cd668711b6a36b5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"req.files[0].buffer","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":60,"wires":[["c0778a29661ad51d"]]},{"id":"447513976bbad321","type":"http response","z":"7dab245d6284333c","g":"2cd668711b6a36b5","name":"","statusCode":"","headers":{},"x":530,"y":100,"wires":[]},{"id":"53ca22d3e64ecf56","type":"change","z":"7dab245d6284333c","g":"2cd668711b6a36b5","name":"Respose File Received","rules":[{"t":"set","p":"payload","pt":"msg","to":"File Received","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":100,"wires":[["447513976bbad321"]]},{"id":"c0778a29661ad51d","type":"function","z":"7dab245d6284333c","g":"2cd668711b6a36b5","name":"Convert Hex to String","func":"const hexBuffer = msg.payload;\n\n// Convert the hex buffer to a Buffer object\nconst buffer = Buffer.from(hexBuffer, 'hex');\n\n// Convert the Buffer to a string\nconst string = buffer.toString();\n\n// Assign the string to msg.payload for further processing\nmsg.payload = string;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":60,"wires":[["8a186079cd832566"]]},{"id":"8a186079cd832566","type":"csv","z":"7dab245d6284333c","g":"2cd668711b6a36b5","name":"","sep":",","hdrin":"","hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":710,"y":60,"wires":[["38e3baae4603771c"]]}]

Flow Info

Created 10 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x2)
  • csv (x1)
  • debug (x1)
  • function (x1)
  • http in (x1)
  • http response (x1)
Other

Tags

  • csv
  • FlowFuse
  • file
  • ingest
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option