public async Task OnBeforeCreateAsync(BeforeCreateContext context) { if (!context.Metadata.ContainsKey("filename")) { context.FailRequest("filename metadata must be specified. "); _logger.LogInformation($"Fileupload failed: filename metadata must be specified"); } if (!context.Metadata.ContainsKey("filetype")) { context.FailRequest("filetype metadata must be specified. "); _logger.LogInformation($"Fileupload failed: filetype metadata must be specified"); } var metadataInString = ""; foreach (var item in context.Metadata) { if (metadataInString.Length != 0) { metadataInString += ", "; } metadataInString += $"\"{item.Key}:{item.Value.GetString(Encoding.UTF8)}\""; } _logger.LogInformation($"Fileupload started: {metadataInString}"); await Task.CompletedTask; }
/// <summary> /// Handle the pre upload required metadata /// </summary> private Task OnBeforeCreate(BeforeCreateContext ctx) { // Partial files are not complete so we do not need to validate the metadata in our example. if (ctx.FileConcatenation is FileConcatPartial) { return(Task.CompletedTask); } if (!ctx.Metadata.ContainsKey("name")) { ctx.FailRequest("name metadata must be specified."); } if (!ctx.Metadata.ContainsKey("contentType")) { ctx.FailRequest("contentType metadata must be specified."); } return(Task.CompletedTask); }