3

I'm implementing a WOPI server in an attempt to integrate with Office Online. When WOPI client calls PutFile method (to save a file) it is sending an empty request (req.body.length === 0). Here's the Node/Express code:

app.post('/wopi/files/:fileId/contents', function (req, res) {
    console.log(req.body.length);
...  

Any suggestions are highly appreciated.

Eesa
  • 2,762
  • 2
  • 32
  • 51
app_sciences
  • 783
  • 1
  • 7
  • 14
  • If you check the request with fiddler or a similar tool, does it contain any additional headers (such as X-WOPI-Size), etc.? Unfortunately, neither the [old](https://msdn.microsoft.com/en-us/library/hh657364(v=office.12).aspx) nor the [new documentation](https://wopi.readthedocs.org/projects/wopirest/en/latest/files/PutFile.html) specify whether the body can or can not be empty under some special circumstances... – rocky Jan 24 '16 at 17:26
  • 1
    Hi @app_sciences did you get it working? I am experiencing the exact same problem. – Eesa Sep 28 '16 at 14:54
  • I am experiencing the exact same problem, did you find any solution? – LazyCreep Jan 08 '18 at 06:18

2 Answers2

3

I found the answer:

Put the following middleware before bodyParser middleware. It'll collect raw body data in request.rawBody and won't interfere with bodyParser.

app.use(function(req, res, next) {
    var data = '';
    req.setEncoding('utf8');
    req.on('data', function(chunk) { 
        data += chunk;
    });
    req.on('end', function() {
        req.rawBody = data;
        next();
    });
});
app.use(express.bodyParser());

for more info see here: https://stackoverflow.com/a/13565786/5976568

Edit:

raw-body-parser, a node package is pretty good, I am using it in my solution.

var rawBodyParser = require('raw-body-parser');

app.use(rawBodyParser());

Getting raw data:

var rawBody = req.rawBody.toString('utf8');
Community
  • 1
  • 1
Eesa
  • 2,762
  • 2
  • 32
  • 51
0

If you are integrating your WOPI Host with the Office Online, I am assuming you or your firm might have already registered with the Microsoft's so called Office 365 Cloud Storage Partner Program

If that's the case then you can approach their active support team in Yammer. There you can post your queries which will be answered diligently.

Soumyaansh
  • 8,626
  • 7
  • 45
  • 45