I am trying to send binary data to azure mobile services API. When we receive the request and try to parse the data , byte values higher than 7f (ie 80,81,90,ff etc..) are interpreted differently. For example if we had sent
Sent data : 67 01 00 00 31 00 31 00 32 00 31 00 00 00 A0 10
Received data: 67 01 00 00 31 00 31 00 32 00 31 00 00 00 ef bf bd 10
This is the curl command:
curl --header "Content-Type:application/octet-stream" -X POST https://x.x.x.x/Api/temp --data-binary @/home/device_data.txt
Nodejs mobile service script Snippet
exports.post = function(request, response) {
var payload=new Buffer(request.body);
console.log(payload);
}
I am suspecting that our 8bit binary stream is being interpreted as 7bit character stream. Can someone please shed some light on this?
The request.body is from ExpressJS- read about it here: http://expressjs.com/4x/api.html#req.body
You will note that request.body is NOT the body of the request - it is a parsed body. You are likely, as a result, to need to explicitly use body-parser to handle the request.
See here as another example of the same thing: nodejs/express and binary data in POST
Also check out body-parser: https://github.com/expressjs/body-parser#bodyparserrawoptions
Unfortunately, I don't believe you can set up additional middleware in the Mobile Services case. One thing you can do is to transition your application over to Azure App Service Mobile Apps - that takes a regular ExpressJS application, but handles authentication, push notifications and data access through an SDK (see https://github.com/Azure/azure-mobile-apps-node and the introductory blog post: https://azure.microsoft.com/en-us/blog/announcing-node-for-azure-mobile-apps/ )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.