コード例 #1
0
        public Task ProcessAsync(BlobProcessHandlerContext context)
        {
            var fileTypeCheckHandlerConfiguration = context.ContainerConfiguration.GetFileTypeCheckConfiguration();

            // TODO: case sensitivity
            if (fileTypeCheckHandlerConfiguration.AllowedFileTypeNames != null && fileTypeCheckHandlerConfiguration.AllowedFileTypeNames.Length > 0)
            {
                string fileExtensionName = Path.GetExtension(context.BlobName);

                if (!fileExtensionName.IsNullOrEmpty())
                {
                    if (!fileTypeCheckHandlerConfiguration.AllowedFileTypeNames.Contains(fileExtensionName.ToLower()))
                    {
                        throw new BusinessException(
                                  code: "Dignite.Abp.BlobStoring:010002",
                                  message: "File type is incompatible!" + "File type should be one of" + fileTypeCheckHandlerConfiguration.AllowedFileTypeNames.JoinAsString("/") + "!",
                                  details: "File type should be one of" + fileTypeCheckHandlerConfiguration.AllowedFileTypeNames.JoinAsString("/") + "!"
                                  );
                    }
                }
                else
                {
                    throw new BusinessException(
                              code: "Dignite.Abp.BlobStoring:010003",
                              message: "File type is unrecognized!",
                              details: "Cannot get the file type of uploaded file!"
                              );
                }
            }
            return(Task.CompletedTask);
        }
コード例 #2
0
        public Task ProcessAsync(BlobProcessHandlerContext context)
        {
            var configuration = context.ContainerConfiguration.GetBlobSizeLimitConfiguration();

            if (configuration.MaximumBlobSize * 1024 * 1024 < context.BlobStream.Length)
            {
                throw new BusinessException(
                          code: "Dignite.Abp.BlobStoring:010008",
                          message: "Blob object is too large",
                          details: $"The blob object size cannot exceed {configuration.MaximumBlobSize}M!"
                          );
            }

            return(Task.CompletedTask);
        }
コード例 #3
0
        public Task ProcessAsync(BlobProcessHandlerContext context)
        {
            var configuration = context.ContainerConfiguration.GetImageResizeConfiguration();

            try
            {
                using (Image image = Image.Load(context.BlobStream))
                {
                    if (configuration.ImageSizeMustBeLargerThanPreset)
                    {
                        if (image.Width < configuration.ImageWidth || image.Height < configuration.ImageHeight)
                        {
                            throw new BusinessException(
                                      code: "Dignite.Abp.BlobStoring:010004",
                                      message: "Image size must be larger than Preset!",
                                      details: "Uploaded image must be larger than: " + configuration.ImageWidth + "x" + configuration.ImageHeight
                                      );
                        }
                    }


                    if (image.Width > configuration.ImageWidth || image.Height > configuration.ImageHeight)
                    {
                        image.Mutate(x =>
                        {
                            x.Resize(new ResizeOptions()
                            {
                                Mode = ResizeMode.Max,
                                Size = new Size(configuration.ImageWidth, configuration.ImageHeight)
                            });
                        });

                        var encoder = new SixLabors.ImageSharp.Formats.Jpeg.JpegEncoder()
                        {
                            Quality = 40
                        };
                        context.BlobStream.Position = 0;
                        image.Save(context.BlobStream, encoder);
                        context.BlobStream.SetLength(context.BlobStream.Position);
                        context.BlobStream.Position = 0;
                    }
                }
            }
            catch (SixLabors.ImageSharp.InvalidImageContentException exception)
            {
            }
            return(Task.CompletedTask);
        }
コード例 #4
0
        private async Task BlobProcessHandlers(string name, Stream stream)
        {
            // blob process handlers
            var processHandlers = Configuration.GetConfigurationOrDefault <ITypeList <IBlobProcessHandler> >(DigniteAbpBlobContainerConfigurationNames.BlobProcessHandlers, null);

            if (processHandlers != null && processHandlers.Any())
            {
                var context = new BlobProcessHandlerContext(name, stream, Configuration, CurrentTenant, ServiceProvider);
                using (var scope = ServiceProvider.CreateScope())
                {
                    foreach (var handlerType in processHandlers)
                    {
                        var handler = scope.ServiceProvider
                                      .GetRequiredService(handlerType)
                                      .As <IBlobProcessHandler>();

                        await handler.ProcessAsync(context);
                    }
                }
            }
        }