WOPI编辑文件

时间:2016-06-24 09:52:56

标签: java onenote ms-wopi

我已经为WOPI客户端(即Office Online)实现了putFile端点 单击编辑文档按钮时,第一个请求应该转到WOPI客户端?

我在编辑链接上调用了以下网址:

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

但文档说它首先会执行锁定请求。它究竟意味着什么?

2 个答案:

答案 0 :(得分:0)

根据您的问题,我了解您正在实施WOPI主机。 URL看起来非常好 - 只需确保转义WOPISrc参数并包含access_token参数。

当您单击URL时,您指示WOPI客户端(OO / OWA)从WOPI主机加载由WOPISrc定义的字段。

WOPI客户端通常首先尝试从WOPI主机获取锁(独占写访问权)。出于这些目的,您应该根据documentation在您的WOPI主机中实现LOCK操作。

答案 1 :(得分:0)

首先,您必须为此添加访问令牌 然后你尝试对它进行单词编辑调用  1.get文件信息。获取[路线(" files / {name} /")]  2.post文件。发布[路线(" files / {name} /")]   听说你必须实现Lock files Cobalt Request的响应        var response = new HttpResponseMessage(HttpStatusCode.OK);                     if(xWopiOverride ==" LOCK" || string.Equals(xWopiOverride," UNLOCK"))                     {                         //对于docx,xl​​sx和pptx                         response = new HttpResponseMessage(HttpStatusCode.OK);                     }                 else if(string.Equals(xWopiOverride," COBALT"))                 {                     //钴,用于docx和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;