Azure Functions Binding Expressions - HTTP Trigger and Blob Storage

%3CLINGO-SUB%20id%3D%22lingo-sub-2087436%22%20slang%3D%22en-US%22%3EAzure%20Functions%20Binding%20Expressions%20-%20HTTP%20Trigger%20and%20Blob%20Storage%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2087436%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20been%20trying%20to%20follow%20the%20example%20in%20the%20following%20documentation%3A%26nbsp%3B%3CA%20title%3D%22Azure%20Functions%20Binding%20Expressions%20and%20Patterns%20-%20JSON%20Payload%22%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-bindings-expressions-patterns%23json-payloads%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Functions%20Binding%20Expressions%20and%20Patterns%20-%20JSON%20Payload%3C%2FA%3E%26nbsp%3Busing%20the%20In%20Portal%20code%20editor.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can't%20get%20it%20to%20work%20and%20I've%20got%20a%20complete%20mental%20block%20on%20how%20to%20solve%20the%20issue.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20code%20compiles%20but%20when%20it%20is%20run%2C%20it%20returns%3A%3CBR%20%2F%3E%3CSPAN%3EExecuted%20%3CEM%3E'functionname'%3C%2FEM%3E%20(Failed%2C%20Id%3D74bde612-9953-4a0b-8e88-e14c32f23b82%2C%20Duration%3D87ms)No%20value%20was%20provided%20for%20parameter%20'req'.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FSPAN%3EWhich%20of%20course%20it%20does!%20Because%20the%20HTTP%20Trigger%20is%20reading%20from%20a%20variable%20called%20'info'%20-%20but%20the%20code%20still%20requires%20'req'%20to%20be%20defined%20but%20it%20doesn't%20have%20a%20value%20until%20it%20is%20given%20a%20value!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHopefully%20someone%20here%20can%20dig%20me%20out%20of%20this%20hole%20because%20I've%20now%20got%20complete%20code%20blindness%20and%20I%20can't%20see%20how%20to%20get%20this%20to%20work...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJust%20for%20ease%2C%20the%20code%20I've%20used%20from%20the%20Microsoft%20documentation%20example%20is%20as%20follows%3A%3C%2FP%3E%3CP%3Efunction.json%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%22bindings%22%3A%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22name%22%3A%20%22info%22%2C%0A%20%20%20%20%20%20%22type%22%3A%20%22httpTrigger%22%2C%0A%20%20%20%20%20%20%22direction%22%3A%20%22in%22%2C%0A%20%20%20%20%20%20%22webHookType%22%3A%20%22genericJson%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22name%22%3A%20%22blobContents%22%2C%0A%20%20%20%20%20%20%22type%22%3A%20%22blob%22%2C%0A%20%20%20%20%20%20%22direction%22%3A%20%22in%22%2C%0A%20%20%20%20%20%20%22path%22%3A%20%22strings%2F%7BBlobName%7D%22%2C%0A%20%20%20%20%20%20%22connection%22%3A%20%22AzureWebJobsStorage%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22name%22%3A%20%22res%22%2C%0A%20%20%20%20%20%20%22type%22%3A%20%22http%22%2C%0A%20%20%20%20%20%20%22direction%22%3A%20%22out%22%0A%20%20%20%20%7D%0A%20%20%5D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Erun.csx%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3Eusing%20System.Net%3B%0Ausing%20Microsoft.Extensions.Logging%3B%0A%0Apublic%20class%20BlobInfo%0A%7B%0A%20%20%20%20public%20string%20BlobName%20%7B%20get%3B%20set%3B%20%7D%0A%7D%0A%20%20%0Apublic%20static%20HttpResponseMessage%20Run(HttpRequestMessage%20req%2C%20BlobInfo%20info%2C%20string%20blobContents%2C%20ILogger%20log)%0A%7B%0A%20%20%20%20if%20(blobContents%20%3D%3D%20null)%20%7B%0A%20%20%20%20%20%20%20%20return%20req.CreateResponse(HttpStatusCode.NotFound)%3B%0A%20%20%20%20%7D%20%0A%0A%20%20%20%20log.LogInformation(%24%22Processing%3A%20%7Binfo.BlobName%7D%22)%3B%0A%0A%20%20%20%20return%20req.CreateResponse(HttpStatusCode.OK%2C%20new%20%7B%0A%20%20%20%20%20%20%20%20data%20%3D%20%24%22%7BblobContents%7D%22%0A%20%20%20%20%7D)%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20know%20there's%20going%20to%20be%20a%20really%20simple%20answer%20to%20this...%20and%20I'm%20going%20to%20kick%20myself%20when%20you%20tell%20me%20it%26nbsp%3B%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fhtml%2Fimages%2Femoticons%2Fsmile_40x40.gif%22%20alt%3D%22%3Asmile%3A%22%20title%3D%22%3Asmile%3A%22%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Senior Member

I have been trying to follow the example in the following documentation: Azure Functions Binding Expressions and Patterns - JSON Payload using the In Portal code editor.

 

I can't get it to work and I've got a complete mental block on how to solve the issue.

 

The code compiles but when it is run, it returns:
Executed 'functionname' (Failed, Id=74bde612-9953-4a0b-8e88-e14c32f23b82, Duration=87ms)No value was provided for parameter 'req'.

Which of course it does! Because the HTTP Trigger is reading from a variable called 'info' - but the code still requires 'req' to be defined but it doesn't have a value until it is given a value!

 

Hopefully someone here can dig me out of this hole because I've now got complete code blindness and I can't see how to get this to work...

 

Just for ease, the code I've used from the Microsoft documentation example is as follows:

function.json:

{
  "bindings": [
    {
      "name": "info",
      "type": "httpTrigger",
      "direction": "in",
      "webHookType": "genericJson"
    },
    {
      "name": "blobContents",
      "type": "blob",
      "direction": "in",
      "path": "strings/{BlobName}",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "res",
      "type": "http",
      "direction": "out"
    }
  ]
}

 

run.csx:

using System.Net;
using Microsoft.Extensions.Logging;

public class BlobInfo
{
    public string BlobName { get; set; }
}
  
public static HttpResponseMessage Run(HttpRequestMessage req, BlobInfo info, string blobContents, ILogger log)
{
    if (blobContents == null) {
        return req.CreateResponse(HttpStatusCode.NotFound);
    } 

    log.LogInformation($"Processing: {info.BlobName}");

    return req.CreateResponse(HttpStatusCode.OK, new {
        data = $"{blobContents}"
    });
}

 

I know there's going to be a really simple answer to this... and I'm going to kick myself when you tell me it :smile:

0 Replies