Search Results for

    Show / Hide Table of Contents

    Client (v6)

    To be able to communicate with the ImageVault service you need a client.

    Creating a client

    To create a client, you use the IClientFactory.

    GetSdkClient

    This is the most common usage for retrieving a client.

    var clientFactory = host.Services.GetRequiredService<IClientFactory>();
    var client = clientFactory.GetSdkClient();
    

    The GetSdkClient should be used when you need full access (depending on the access level of the client credentials) to ImageVault or need to create public urls.

    Sdk client without publishing urls

    When you use the GetSdkClient you will most often get a client that only generates public urls. To retrieve a client that has the same user context as the SdkClient but without generating published urls, just clear the PublishIdentifier property from the client.

    var clientFactory = host.Services.GetRequiredService<IClientFactory>();
    var client = clientFactory.GetSdkClient();
    client.PublishIdentifier = null;
    

    Alternatively, use the Client constructor and pass the current configuration to it.

    //read current configuration
    var options = host.Services.GetRequiredService<IOptions<ImageVaultClientOptions>>().Value;
    //clear any existing publish identifier
    options.PublishIdentifier = null;
    //clear any existing publish identifier generator
    options.PublishIdentifierGenerator = null;
    var objectCache = host.Services.GetRequiredService<IObjectCache>();
    var client = new global::ImageVault.Client.Client(options, objectCache);
    

    GetCurrentUserClient

    This client can be used if you need to apply the current user access rights for the API calls.

    var clientFactory = host.Services.GetRequiredService<IClientFactory>();
    var client = clientFactory.GetCurrentUserClient();
    

    When using the GetCurrentUserClient you will produce internal urls and the result will be filtered by the users access rights so only the media available to the user (and the client) will be displayed.

    Using the Client constructor

    You can also use the Client(ClientConfigurationSection) but then you need to set all configuration by yourself and pass it to the constructor.

    //read current configuration
    var options = new ImageVaultClientOptions
    {
        Url = new Uri("https://my.imagevault.app"),
        SdkUser = new CredentialsOptions
        {
            Username = "mySdkUser",
            Password = "mySdkPassword"
        }
    };
    var objectCache = host.Services.GetRequiredService<IObjectCache>();
    var client = new global::ImageVault.Client.Client(options, objectCache);
    

    Internal vs Public media urls

    If you specify the PublishIdentifier you will get public media urls. If it isn't defined, you will get internal urls.

    When requesting a client using the GetCurrentUserClient, the PublishIdentifier is not set.

    When requesting a client using the GetSdkClient the PublishIdentifier is automatically populated with the value from the SdkPublishIdentifier (or the SdkPublishIdentifierGenerator).

    Read more about media urls in the documentation.

    Note

    A publish identifier is also the key that identifies a site and you cannot have more different publishing sites than your license allows.

    In This Article
    Back to top (c) Meriworks 2002-2022