dapr / dotnet-sdk

Dapr SDK for .NET
Apache License 2.0
1.12k stars 341 forks source link

How to set ContentType header when using azure blob storage binding #1135

Open ekjuanrejon opened 1 year ago

ekjuanrejon commented 1 year ago

How to set ContentType header when using azure blob storage binding?

philliphoff commented 1 year ago

@ekjuanrejon You can control the content-type associated to the blob by setting the contentType metadata when invoking the binding.

using Dapr.Client;

var daprClient = new DaprClientBuilder().Build();

Console.WriteLine("Invoking binding...");

await daprClient.InvokeBindingAsync(
    "blob-storage",
    "create",
    new { data = "Hello, World!" },
    new Dictionary<string, string>
    {
        { "blobName", "hello.txt" },
        { "contentType", "application/json" }
    });

Console.WriteLine("Done!");

In the above example, the blob will be associated with the application/json content type (vs. a default of application/octet-stream, if no metadata were set).

Let us know if you're not finding otherwise.