如何在 NodeJS 中检索通过 API 调用发送的 blob 数据?
How to retrieve blob data sent over API call in NodeJS?
我通过 API 调用从 ReactJS 发送了 blob 数据,我的节点服务器正在侦听该端口。
const audioBlob = new Blob(audioChunks, { type: 'audio/wav'});
let fd = new FormData();
fd.append('audio', audioBlob);
axios.post('http://localhost:3001/generateConsolidatedAudio', {
data: fd });
节点 JS:
const express = require('express');
const router = express.Router();
const app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.text());
router.post('/generateConsolidatedAudio', function(req, res, next) {
res.send('Hello Gi');
}));
我做了 console.log(req.body)
和 console.log(req.data)
,但都是 undefined
。
我想从中获取 blob 并将其转换为 WAV 文件。请帮忙?
最好将 blob 转换为文件并发送文件
const audioBlob = new Blob(audioChunks, { type: 'audio/wav'});
var audioFile = new File([audioBlob], "name");
let fd = new FormData();
fd.append('audio', audioFile);
axios.post('http://localhost:3001/generateConsolidatedAudio', {
data: fd });
现在在 Nodejs 中您无法使用 body-parser
处理文件或多部分数据。所以使用 multer npm i multer
我通过 API 调用从 ReactJS 发送了 blob 数据,我的节点服务器正在侦听该端口。
const audioBlob = new Blob(audioChunks, { type: 'audio/wav'});
let fd = new FormData();
fd.append('audio', audioBlob);
axios.post('http://localhost:3001/generateConsolidatedAudio', {
data: fd });
节点 JS:
const express = require('express');
const router = express.Router();
const app = express();
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.text());
router.post('/generateConsolidatedAudio', function(req, res, next) {
res.send('Hello Gi');
}));
我做了 console.log(req.body)
和 console.log(req.data)
,但都是 undefined
。
我想从中获取 blob 并将其转换为 WAV 文件。请帮忙?
最好将 blob 转换为文件并发送文件
const audioBlob = new Blob(audioChunks, { type: 'audio/wav'});
var audioFile = new File([audioBlob], "name");
let fd = new FormData();
fd.append('audio', audioFile);
axios.post('http://localhost:3001/generateConsolidatedAudio', {
data: fd });
现在在 Nodejs 中您无法使用 body-parser
处理文件或多部分数据。所以使用 multer npm i multer