Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        private static Task <bool> HandleOnBeforeCreateAsync(ContextAdapter context, bool supportsUploadConcat,
                                                             UploadConcat uploadConcat, string metadata, long uploadLength)
        {
            if (context.Configuration.Events?.OnBeforeCreateAsync == null)
            {
                return(Task.FromResult(false));
            }

            return(HandleOnBeforeCreateAsyncLocal());

            async Task <bool> HandleOnBeforeCreateAsyncLocal()
            {
                var beforeCreateContext = BeforeCreateContext.Create(context, ctx =>
                {
                    ctx.FileConcatenation = supportsUploadConcat ? uploadConcat.Type : null;
                    ctx.Metadata          = Metadata.Parse(metadata);
                    ctx.UploadLength      = uploadLength;
                });

                await context.Configuration.Events.OnBeforeCreateAsync(beforeCreateContext);

                if (beforeCreateContext.HasFailed)
                {
                    return(await context.Response.Error(HttpStatusCode.BadRequest, beforeCreateContext.ErrorMessage));
                }

                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <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);
        }
 public Task HandleBeforeCreate(BeforeCreateContext context)
 {
     return(Task.CompletedTask);
 }