首页 > 解决方案 > 将 ImageFlow 服务器与多个 Azure 容器一起使用

问题描述

我目前正在评估 ImageFlow Server ( https://github.com/imazen/imageflow-dotnet-server ) 以确定它是否能满足我正在从事的项目的需求。通过文档,我能够使用以下命令将 ImageFlow 服务器连接到 Azure 存储:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddImageflowAzureBlobService(
            new AzureBlobServiceOptions("[MY CONNECTION STRING TO AZURE STORAGE]",
                    new BlobClientOptions())
                .MapPrefix("/azure", "[CONTAINER No. 1]"));
    }

这没有问题,我可以按预期看到图像。该项目的当前要求要求每个用户都有一个唯一的容器,这使得上述实现变得不可能。

有没有办法在发出请求时将容器名称与文件名一起传递?类似于:'/azure/CONTAINER/image.jpg?w=250'

标签: imageresizerimageflow

解决方案


我们在这里有一个示例提供程序可以做到这一点:https ://github.com/imazen/imageflow-dotnet-server/blob/main/examples/Imageflow.Server.Example/CustomBlobService.cs

// Custom blob services can do whatever you need. See CustomBlobService.cs in src/Imageflow.Service.Example
            services.AddImageflowCustomBlobService(new CustomBlobServiceOptions()
            {
                Prefix = "/custom_blobs/",
                IgnorePrefixCase = true,
                ConnectionString = "UseDevelopmentStorage=true;",
                // Only allow 'my_container' to be accessed. /custom_blobs/my_container/key.jpg would be an example path.
                ContainerKeyFilterFunction = (container, key) =>
                    container == "my_container" ? Tuple.Create(container, key) : null
            });

推荐阅读