public async Task <IActionResult> Execute(ReceiveContentArgs content, DestinationArgs destination) { //TODO deeper validation if (content == null || destination == null) { return(new OkResult()); } //This was begging for a Try... var result = await _BlobWriter.Write(content, destination); if (!result.ItemAddedOrOverwritten) { return(new ConflictResult()); } var path = destination.Name.Equals(EndPointNames.ManifestName) ? string.Concat(destination.Path, "/", EndPointNames.ManifestName) : string.Concat(destination.Path, "/", content.PublishingId); var mutable = destination.Name.Equals(EndPointNames.ManifestName); await _QueueSender.Send(new StorageAccountSyncMessage { RelativePath = path, MutableContent = mutable }); return(new OkResult()); }
public async Task <IActionResult> UploadFile( [FromForm] UploadFileRequest fileData, [FromRoute] string directoryId, [FromQuery(Name = "revisionNr")] uint?revisionNumber) { #region - Input data validation if (!IdGenerator.TypeFromId(directoryId, out var typOfId) || typOfId != IdType.Directory) { return(BadRequest()); } if (fileData.File == null || fileData.File.Length <= 0 || fileData.File.Length > int.MaxValue || fileData.File.Length > config.Value.ValidationRules.MaxFileSizeInBytes || string.IsNullOrWhiteSpace(fileData.Name) || string.IsNullOrWhiteSpace(fileData.EncryptedKey) || string.IsNullOrWhiteSpace(fileData.PlaintextKey)) { return(BadRequest()); } var fileSize = (int)fileData.File.Length; var plaintextKeyBytes = Convert.FromBase64String(fileData.PlaintextKey); // Make sure the iv is 16 Bytes long and the key has exactly 32 Byte. if (plaintextKeyBytes.Length != 16 + 32) { return(BadRequest()); } #endregion var fileId = IdGenerator.NewId(IdType.File); try { // Upload file to bucket var successful = await bucket.UploadFileEncrypted( config.Value.ExternalServices.MinioBucketName, fileId, fileSize, plaintextKeyBytes, fileData.File.OpenReadStream()); if (!successful) { return(BadRequest()); } // Add item to database var quickNumber = await guardApi.AddFile( directoryId, fileId, fileSize, fileData.EncryptedKey, DocumentLanguage.German, ExtensionType.Docx); // Add item to queue var queueRequest = new QueueFileMetadataDto { FileId = fileId, DirectoryId = directoryId, DocumentLanguage = fileData.DocumentLanguage, EncryptedKey = fileData.EncryptedKey, FileName = fileData.Name, PlaintextKey = fileData.PlaintextKey }; await queueSender.Send(queueRequest); // Build response // TODO Remove casts and add uint return values in sub-apis var response = new UploadFileResponse( queueRequest.FileName, fileId, (uint)fileSize, DateTime.UtcNow, DateTime.MinValue, (uint)quickNumber); return(Ok(response)); } catch (Exception e) { // TODO Remove file if something failed Console.Write(e); return(BadRequest()); } }