簡體   English   中英

Azure Function 中的可選變量由 BLOB 觸發

[英]Optional variables in Azure Function triggered by BLOB

When configuring a blob trigger for an Azure function, it is possible to use pattern matching on the blob name to map portions of the name, to variables in the function. 例如:

[FunctionName("BlobTriggered")]        
public static void BlobTriggered(
    [BlobTrigger("myContainer/{name}.{extension}")] Stream myBlob,
    string name,
    string extension,
    TraceWriter log)
{
    ...
}

但是,如果我希望其中一個變量是可選的呢? 對於給定的示例,如果我希望擴展是可選的怎么辦? 因此,我需要制作. ,以及擴展本身,是可選的。 這有可能實現嗎?

您可以像這樣刪除模式並自己處理文件名和擴展名。

    public static void Run([BlobTrigger("test/{name}", Connection = "teststorage_STORAGE")]Stream myBlob, string name, ILogger log)
    {
        log.LogInformation($"Name: {Path.GetFileName(name)}");
        log.LogInformation($"Extension: {Path.GetExtension(name)}");
    }

在第一次上傳帶有擴展名而最后一次不帶擴展名的下方記錄條目。

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM