You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

创建Node-RED流程:接收本地文件上传并调用Spring Boot上传接口

Alright, let's get this Node-RED flow up and running to handle file uploads and pass them to your Spring Boot endpoint. Here's a step-by-step breakdown:

Step 1: Set up the HTTP Input Node

Drag an HTTP In node onto your flow and configure it like this:

  • Method: POST
  • URL: /uploadFile
  • Check the box for Accept file uploads (this lets Node-RED handle multipart/form-data uploads from your HTML form)
  • Leave other settings as default, then deploy the node.
Step 2: Add a Function Node to Process the Uploaded File

Next, add a Function node and wire it to the HTTP In node. Paste this code into the function editor to format the file for your Spring Boot endpoint:

// Grab the first uploaded file from the incoming request
const uploadedFile = msg.req.files[0];

// Build the multipart/form-data payload that Spring Boot expects
msg.payload = {
  userFile: {
    value: uploadedFile.buffer,
    options: {
      filename: uploadedFile.originalname,
      contentType: uploadedFile.mimetype
    }
  }
};

// Set the content type (Node-RED will auto-generate the boundary for you)
msg.headers = {
  'Content-Type': 'multipart/form-data'
};

return msg;

This code takes the file from the incoming request, packages it into the userFile parameter your Spring Boot endpoint is expecting, and sets the correct headers.

Step 3: Add and Configure the HTTP Request Node

Drag an HTTP Request node onto the flow and wire it to the Function node. Configure it as follows:

  • Method: POST
  • URL: http://localhost:8080/uploadFile
  • Return: a parsed JSON object (or plain text, depending on what your Spring Boot endpoint returns)
  • Leave other settings default, then deploy.
Step 4: Add an HTTP Response Node

Finally, add an HTTP Response node and wire it to the HTTP Request node. This sends the response from your Spring Boot endpoint back to the user's browser. You can leave its settings as default.

Test the Flow

Create a simple local HTML file to test the upload:

<!DOCTYPE html>
<html>
<body>
  <h3>Upload File to Node-RED</h3>
  <form action="http://localhost:1880/uploadFile" method="post" enctype="multipart/form-data">
    <input type="file" name="file" required>
    <button type="submit">Upload</button>
  </form>
</body>
</html>

Open this HTML file in your browser, select a file, and click "Upload". Node-RED will receive the file, forward it to your Spring Boot endpoint, and return whatever response your Spring Boot app sends back.

A quick heads-up: Make sure both Node-RED (running on port 1880) and your Spring Boot app (port 8080) are running simultaneously when you test!

内容的提问来源于stack exchange,提问作者Florin S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:42:37