首先,您必須爲此 添加Access令牌,然後嘗試對其進行編輯調用 1.get file info。獲取[路線(「文件/ {名稱} /」)] 2.post文件。 Post [路由(「文件/ {名稱} /」)] 聽說你必須實現對鎖定文件的響應Cobalt請求 var response = new HttpResponseMessage(HttpStatusCode.OK); (xWopiOverride ==「LOCK」|| string.Equals(xWopiOverride,「UNLOCK」)) {0}對於docx,xlsx和pptx response = new HttpResponseMessage(HttpStatusCode.OK); } 否則如果(string.Equals(xWopiOverride, 「鈷」)) { //鈷,對於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;
休耕此https://github.com/petrsvihlik/WopiHost –