Question

Situation : Client js sends ajax request to nodejs express server.

Client

xmlHttpRequest=new XMLHttpRequest();  
xmlHttpRequest.open("POST","/some/server/path,true);
xmlHttpRequest.responseType="arraybuffer";
xmlHttpRequest.send(new Uint8Array(arraybufferobject));

Server(so far)

var express = require('express');
var server = express();
server.use(express.static(__dirname));
server.use(express.bodyParser());
server.post('/goforms/modbus/',function(req,res,next){
    //How to access the uint8array || arraybuffer ?
});

server.listen(80);

Im stuck at this point. How to access the HTTP POST data?

Was it helpful?

Solution

The bodyParser middleware does not parse POSTed binary data. When i tried base64 encoded strings, it would show up as the object name in a JSON object, something like {"data":}, obviously expecting POST-data in the form name=value.

There might be a middleware that deals with binary data, or you can access the raw data by binding to the "data" event and stack the received chunks into a buffer using the method described in the ProtocolBuffers.js wiki.

This is using the vanilla http module without express, but should work anyway.

OTHER TIPS

I don't know about arraybuffer but usually, we can access the POST data using the req.body parameter. Does that work for you?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top