Javascript 将jpeg文件从webcam.js上载到nodejs服务器
我调用了Javascript 将jpeg文件从webcam.js上载到nodejs服务器,javascript,node.js,webcam.js,Javascript,Node.js,Webcam.js,我调用了webcam.js库的snap函数,得到了base64格式的图像数据。我想把那个文件上传到nodejs服务器。我调用了webcam.upload()函数,在request.body中得到一个空对象。 客户端代码如下所示 Webcam.snap( function(data_uri) { Webcam.on( 'uploadProgress', function(progress) { // Upload in progress
webcam.js
库的snap函数,得到了base64
格式的图像数据。我想把那个文件上传到nodejs服务器。我调用了webcam.upload()
函数,在request.body
中得到一个空对象。
客户端代码如下所示
Webcam.snap( function(data_uri) {
Webcam.on( 'uploadProgress', function(progress) {
// Upload in progress
console.log(progress);
// 'progress' will be between 0.0 and 1.0
} );
Webcam.on( 'uploadComplete', function(code, text) {
// Upload complete!
// 'code' will be the HTTP response code from the server, e.g. 200
console.log(code);
// 'text' will be the raw response content
console.log(text);
} );
Webcam.upload( data_uri, '/image' );
} )
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.post("/image", function(request, response) {
console.log(request.body);
response.send("OK");
});
服务器端代码如下所示
Webcam.snap( function(data_uri) {
Webcam.on( 'uploadProgress', function(progress) {
// Upload in progress
console.log(progress);
// 'progress' will be between 0.0 and 1.0
} );
Webcam.on( 'uploadComplete', function(code, text) {
// Upload complete!
// 'code' will be the HTTP response code from the server, e.g. 200
console.log(code);
// 'text' will be the raw response content
console.log(text);
} );
Webcam.upload( data_uri, '/image' );
} )
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.post("/image", function(request, response) {
console.log(request.body);
response.send("OK");
});
假设您使用的是Express,那么是否包含体解析器?是的,包含体解析器。使用json解析器并以json格式发送数据
webcam.upload({data:datauri},'/image')
但是检查webcam.jswebcam.upload({data:datauri},'/image')中是否允许对象发送代码>这在webcamjs中是不允许的。您能帮助解决这个问题吗?假设您使用的是Express,是否包含正文解析器?是的,包含正文解析器。使用json解析器并以json格式发送数据webcam.upload({data:datauri},'/image')
但是检查webcam.jswebcam.upload({data:datauri},'/image')中是否允许对象发送代码>这在webcamjs中是不允许的。你能帮我解决这个问题吗。