I'm triggering an Azure Function with HTTP POST and would like to save the request body to a Blob. Per the documentation this should be relatively straight forward using the output Blob storage binding. However, I was not able to get it to work. When I check the auto-generated function.json, I notice there is no binding created for the output.
The following function is working, but I would like to know what I am missing regarding the Blob output binding. How would you go about changing this to use Blob output binding?
public static class SaveSubContent
{
[FunctionName("SaveSubContent")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context
)
{
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
var connectionString = config["AzureWebJobsStorage"];
string containerName = "france-msgs";
string blobName = Guid.NewGuid().ToString() + ".json";
BlobContainerClient container = new BlobContainerClient(connectionString, containerName);
container.CreateIfNotExists();
BlobClient blob = container.GetBlobClient(blobName);
blob.Upload(req.Body);
log.LogInformation("Completed Uploading: " + blobName);
return new OkObjectResult("");
}
}