Office WebAppsIn one of our projects we had an interesting challenge, how could we preview documents stored on an SQL Database using Office Web Apps (like we see in SharePoint). To accomplish that we created a Wopi Host and in this blog post we will briefly explain how a Wopi Host works and how it allowed us to preview documents using OWA.

So, how can we request a preview?

First we  must know what app to use to open the document and if it is available on our current installation of Office Web Apps. That is done through the Discovery.xml, there we can find information about the apps available and to what url we must do the request. You can find this file under /hosting/discovery on your Office Web Apps. With that we have the first part of our preview url (example for a word document):

http://owa/wv/wordviewerframe.aspx

After that we must tell Office Web Apps how to get the document. This is where the Wopi Host comes into play. Here we will have the wopi host url and the file name/id and it will be sent as a query string parameter to office web apps:

?WOPISrc=https://wopihost/api/wopi/files/{filename}?access_token={access token}&access_token_ttl={time to live}

  • File Name: string representing the file to be opened. It must represent a single file and be URL-safe;
  • Access Token: a string that can be used to determine the identity and permissions of the issuer of the request;
  • Access Token Time to Live: tell the WOPI client when the access token expires. It is represented as the number of milisecondes since January 1, 1970 UTC;

With the complete URL all we have to do is get it into an iframe, after that all the calls/exchange of information will be handle by Office Web Apps and our Wopi Host. We need to implement the following methods in our wopi api:

GetFileInfo

Here the Office Web Apps will be expecting to receive information about the file:

  • BaseFileName [string]: name of the file including extension, without a path
  • OwnerId [string]: unique identifier of the owner of the file
  • Size [long]: size of the file in bytes
  • UserId [string]: unique identifier of the user accessing the file
  • Version [string]: file version

Get

Here we will return the binary content of the file to Office Web Apps.

Summarizing

In order to use Office Web Apps to preview our documents stored into SQL we first must tell it how to obtain them. To do that we must build the URL as explained above.

With the URL ready, we place it into an iframe which will start the chain of requests between the Office Web Apps and our Wopi Host in order to get the file info and binary content.

You can get a complete overview of the WOPI REST API Reference here and you can find an working example of a wopi host here .


1 Comment

Rakesh Sorathiya · July 2, 2020 at 2:54 pm

Hi,

Currently we want to enable feature in web based application where external users can view and edit word document. Application is developed using angular and Spring REST services.
Documents are stored on AWS S3.

Do you provide WOPI integration implementation which can enable this feature?

Thank You,
Rakesh Sorathiya.

Leave a Reply to Rakesh Sorathiya Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: