user2846382
user2846382

Reputation: 385

WOPI Editing Document

I have implemented the putFile endpoint for WOPI client (i.e. Office Online) When clicking the edit document button, what should be the first request go to WOPI client?

I have called following URL on edit link:

POST https://word-edit.officeapps-df.live.com/we/wordviewerframe.aspx?WOPISrc=https://domain/WOPI_IntegrationDemo/wopi/files/Sample_application_content3.docx/

But document says that it'll perform a lock request first. What does it mean exactly?

Upvotes: 0

Views: 1585

Answers (2)

Lovindu Bandara
Lovindu Bandara

Reputation: 41

First you must Add Access token for this then you try to word edit it call to 1.get file info. Get [Route("files/{name}/")] 2.post file. Post [Route("files/{name}/")] in hear you have to implement response for Lock files Cobalt Request var response = new HttpResponseMessage(HttpStatusCode.OK); if (xWopiOverride == "LOCK" || string.Equals(xWopiOverride, "UNLOCK")) { //for docx, xlsx and pptx response = new HttpResponseMessage(HttpStatusCode.OK); } else if (string.Equals(xWopiOverride, "COBALT")) { //cobalt, for docx and pptx

                EditSession editSession = EditSessionManager.Instance.GetSession(access_token);
                if (editSession == null)
                {
                    editSession = new FileSession(access_token, fileInfo, matterInfo, dpsUserName, databaseInfo, string.Empty, string.Empty, string.Empty, false);
                    EditSessionManager.Instance.AddSession(editSession);
                }

                var memoryStream = new MemoryStream();
                HttpContext.Current.Request.InputStream.CopyTo(memoryStream);
                var atomFromByteArray = new AtomFromByteArray(memoryStream.ToArray());

                ProtocolVersion protocolVersion;
                object context;
                var requestBatch = new RequestBatch();
                requestBatch.DeserializeInputFromProtocol(atomFromByteArray, out context, out protocolVersion);
                editSession.ExecuteRequestBatch(requestBatch);

                foreach (var request in requestBatch.Requests)
                {
                    if (request.GetType() == typeof(PutChangesRequest) && request.PartitionId == FilePartitionId.Content)
                    {
                        editSession.Save();
                        break;
                    }
                }

                var responseContent = requestBatch.SerializeOutputToProtocol(protocolVersion, context);
                var correlationId = Request.Headers.GetValues("X-WOPI-CorrelationID").First();

                response.Headers.Add("X-WOPI-CorrelationID", correlationId);
                response.Headers.Add("request-id", correlationId);

                var pushStreamContent = new PushStreamContent((outputStream, httpContext, transportContent) =>
                {
                    responseContent.CopyTo(outputStream);
                    outputStream.Close();
                });

                response.Content = pushStreamContent;
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response.Content.Headers.ContentLength = responseContent.Length;
            }
            return response; 

Upvotes: 0

rocky
rocky

Reputation: 7696

From your question I understand that you're implementing a WOPI host. The URL looks pretty much ok - just make sure the WOPISrc parameter is escaped and that you include access_token parameter.

When you click the URL you instruct the WOPI client (OO/OWA) to load a field defined by WOPISrc from WOPI host.

The WOPI client usually tries to acquire a lock (exclusive write access) from WOPI host first. For those purposes you should implement the LOCK operation in your WOPI host according to the documentation.

Upvotes: 0

Related Questions