我想将一个 blob 数据从 JA 客户端发送到 NodeJS 服务器。
现在我有这个客户端代码: [...] recorder.exportWAV(function(blob) { audioObj = blob; });
var formData = new FormData();
formData.append("operation", "addMessage");
formData.append("msg", audioObj);
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:8080/sendRecord", true);
xhr.onreadystatechange = function(){
if(xhr.readyState==4 && xhr.status==200){
// get response from server
}
}
xhr.send(formData);
我使用一些 JS 库从集成麦克风录制音频,最后我有一个音频对象,它是一个 blob 对象。
我想调整这个 si node.js 服务器以接收数据。
var http = require('http'),
url = require('url');
var app = http.createServer(function(request, response){
var path = url.parse(request.url).pathname;
// check the url path
if (path == "/sendRecord") {
// check the request method
if(request.method != "POST"){
// return error
}
// _______________________________
//| here I want catching XHR data |
// –––––––––––––––––––––––––––––––
}
}).listen(8080);
console.log("Server running on: http://localhost:8080/");
我认为应该是一些用于响应客户端 XHR 请求的服务器端 XHR API,但我不知道在哪里可以找到它们。有人可以帮我吗?还带有链接或文档... ;)
谢谢!