add backend(model)
This commit is contained in:
38
lib/backend_model/index.js
Normal file
38
lib/backend_model/index.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const multer = require('multer');
|
||||||
|
const bodyParser = require('body-parser');
|
||||||
|
|
||||||
|
// 创建 express 应用
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
// 不需要保存文件,只使用内存存储
|
||||||
|
const storage = multer.memoryStorage();
|
||||||
|
const upload = multer({ storage: storage }); // 使用内存存储,不会保存文件到硬盘
|
||||||
|
|
||||||
|
// 解析 JSON 请求体
|
||||||
|
app.use(bodyParser.json());
|
||||||
|
|
||||||
|
// 创建一个 POST 接口来接收上传的图片
|
||||||
|
app.post('/api/upload', upload.single('image'), (req, res) => {
|
||||||
|
// 这里返回固定的物体检测结果,不需要保存文件
|
||||||
|
const fixedResponse = {
|
||||||
|
// success: true,
|
||||||
|
// message: '物体检测成功',
|
||||||
|
// result: {
|
||||||
|
objects: [
|
||||||
|
{ name: 'Person', confidence: 0.98 },
|
||||||
|
{ name: 'Car', confidence: 0.92 },
|
||||||
|
{ name: 'Dog', confidence: 0.85 },
|
||||||
|
]
|
||||||
|
// }
|
||||||
|
};
|
||||||
|
|
||||||
|
// 返回固定的分析结果
|
||||||
|
res.status(200).send(fixedResponse);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 启动服务器
|
||||||
|
const PORT = 3000;
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
console.log(`服务器已启动,监听端口 ${PORT}`);
|
||||||
|
});
|
||||||
1586
lib/backend_model/package-lock.json
generated
Normal file
1586
lib/backend_model/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
18
lib/backend_model/package.json
Normal file
18
lib/backend_model/package.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"name": "backend_model",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"start": "node index.js"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"body-parser": "^2.2.1",
|
||||||
|
"express": "^5.2.1",
|
||||||
|
"multer": "^2.0.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user