0

How do I use the body of my queue message to bind to my input blob?

The value I would need to capture would be myj.json.

I've got a queue triggered function:

[FunctionName ("OnSaveXmlBytesBlobTriggered")]
public static void Run (
    [QueueTrigger ("xmlinputqueue", Connection = "mystorconn")] JObject myQueueItem, 
    [Blob ("xmlinput/{jsonFileName}", FileAccess.Read, Connection = "mystorconn")] Stream blobInput,
    ILogger log) {

    log.LogInformation ($"C# Queue trigger function processed: {myQueueItem.subject}");
}

Here's a sample of the myQueueItem:

{
    "topic": "/subscriptions/xxxxxxxxxxx/resourceGroups/myresourcegroup/providers/Microsoft.Storage/storageAccounts/mystoraccount",
    "subject": "/blobServices/default/containers/xmlinput/blobs/myj.json",
    "eventType": "Microsoft.Storage.BlobCreated",
    "eventTime": "2019-05-20T18:58:28.7390111Z",
    "id": "xxxxxxxxxxxxxxxx",
    "data": {
        "api": "PutBlockList",
        "clientRequestId": "xxxxxxxxxxxxxxxx",
        "requestId": "xxxxxxxxxxxxxxxx",
        "eTag": "0x8D6DD55254EBE75",
        "contentType": "application/json",
        "contentLength": 874636,
        "blobType": "BlockBlob",
        "url": "https://mystoraccount.blob.core.windows.net/xmlinput/myj.json",
        "sequencer": "00000000000000000000000000005FAC0000000000614963",
        "storageDiagnostics": {
            "batchId": "xxxxxxxxxxxxxxxx"
        }
    },
    "dataVersion": "",
    "metadataVersion": "1"
}

How do a string inside of the queue payload body, in order to bind to my input blob?

Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062

1 Answers1

1

You will want to convert the JToken to a string, search for the last slash position and then substring everything that is ahead of it.

string url = myQueueItem["data"]["url"].ToString();
int pos = url.LastIndexOf("/") + 1;
Console.WriteLine(url.Substring(pos, url.Length - pos));

Will return myj.json

Carlos Alves Jorge
  • 1,919
  • 1
  • 13
  • 29
  • :) appreciate it, but im looking specifically for an answer that does this automatically with bindings – Alex Gordon May 20 '19 at 21:25
  • Ah. got it... Probably this answer points in the direction you are looking then... https://stackoverflow.com/questions/42991415/best-way-to-pass-multiple-blob-inputs-to-a-queuetrigger-azure-function – Carlos Alves Jorge May 20 '19 at 21:31
  • Yes, as in the answer @CarlosAlvesJorge linked to above. Define your POCO class and then just replace JObject with that object. – ahmelsayed May 20 '19 at 22:33