/// <summary> /// Processes a GetFile request /// </summary> /// <remarks> /// For full documentation on GetFile, see https://wopi.readthedocs.org/projects/wopirest/en/latest/files/GetFile.html /// </remarks> private async static Task <HttpResponseMessage> GetFile(this HttpContext context, FileModel file) { // Get the file from blob storage var bytes = await AzureStorageUtil.GetFile(file.id.ToString(), file.Container); // Write the response and return success 200 var response = returnStatus(HttpStatusCode.OK, "Success"); response.Content = new ByteArrayContent(bytes); return(response); }
/// <summary> /// Processes a PutFile request /// </summary> /// <remarks> /// For full documentation on PutFile, see https://wopi.readthedocs.org/projects/wopirest/en/latest/files/PutFile.html /// </remarks> private async static Task <HttpResponseMessage> PutFile(this HttpContext context, FileModel file) { // Get the Lock value passed in on the request string requestLock = context.Request.Headers[WopiRequestHeaders.LOCK]; // Ensure the file has a valid lock if (String.IsNullOrEmpty(file.LockValue)) { // If the file is 0 bytes, this is document creation if (context.Request.InputStream.Length == 0) { // Update the file in blob storage var bytes = new byte[context.Request.InputStream.Length]; context.Request.InputStream.Read(bytes, 0, bytes.Length); file.Size = bytes.Length; await AzureStorageUtil.UploadFile(file.id.ToString(), file.Container, bytes); // Update version file.Version++; await DocumentRepository <FileModel> .UpdateItemAsync("Files", file.id.ToString(), (FileModel)file); // Return success 200 return(returnStatus(HttpStatusCode.OK, "Success")); } else { // File isn't locked...pass empty Lock in mismatch response return(context.returnLockMismatch(String.Empty, "File isn't locked")); } } else if (file.LockExpires != null && file.LockExpires < DateTime.Now) { // File lock expired, so clear it out file.LockValue = null; file.LockExpires = null; await DocumentRepository <FileModel> .UpdateItemAsync("Files", file.id.ToString(), (FileModel)file); // File isn't locked...pass empty Lock in mismatch response return(context.returnLockMismatch(String.Empty, "File isn't locked")); } else if (requestLock != file.LockValue) { // File lock mismatch...pass Lock in mismatch response return(context.returnLockMismatch(file.LockValue, "Lock mismatch")); } else { // Update the file in blob storage var bytes = new byte[context.Request.InputStream.Length]; context.Request.InputStream.Read(bytes, 0, bytes.Length); file.Size = bytes.Length; await AzureStorageUtil.UploadFile(file.id.ToString(), file.Container, bytes); // Update version file.Version++; await DocumentRepository <FileModel> .UpdateItemAsync("Files", file.id.ToString(), (FileModel)file); // Return success 200 return(returnStatus(HttpStatusCode.OK, "Success")); } }