首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何捕获队列触发器绑定中的子字符串并将其用于输入blob绑定?

如何捕获队列触发器绑定中的子字符串并将其用于输入blob绑定?
EN

Stack Overflow用户
提问于 2019-05-21 04:45:30
回答 1查看 67关注 0票数 0

如何使用队列消息体绑定到输入blob?

我需要捕获的值是myj.json

我有一个队列触发函数:

代码语言:javascript
复制
[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}");
}

下面是myQueueItem的一个示例

代码语言:javascript
复制
{
    "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"
}

为了绑定到我的输入blob,队列有效负载主体中的字符串应该怎么做?

EN

回答 1

Stack Overflow用户

发布于 2019-05-21 05:19:54

您需要将JToken转换为字符串,搜索最后一个斜杠位置,然后子串前面的所有内容。

代码语言:javascript
复制
string url = myQueueItem["data"]["url"].ToString();
int pos = url.LastIndexOf("/") + 1;
Console.WriteLine(url.Substring(pos, url.Length - pos));

将返回myj.json

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56227951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档