imageresizerimageflow

Using ImageFlow Server with multiple Azure Containers


I am currently evaluating ImageFlow Server (https://github.com/imazen/imageflow-dotnet-server) to determine if it will meet the needs of a project that I am working on. Working through the documentation, I was able to get the ImageFlow Server connected to Azure Storage using the following:

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

This works without issue and I can see images as expected. Current requirements for the project requires that each user will have a unique container though, which makes the implementation above impossible.

Is there a way to pass the container name along with the file name when making a request? Something like: '/azure/CONTAINER/image.jpg?w=250'


Solution

  • We have an example provider to do exactly that here: 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
                });