如何配置Blob Trigger绑定以排除含Thumbnails的URL路径?
The pattern you tried (BlobTrigger("ProfilePhoto/*~thumbnails*/{name}")) doesn't work because Azure Functions Blob Triggers use glob matching (not regular expressions), and the ~ character is treated as a literal here. This means your pattern is actually looking for blobs with ~thumbnails~ in their path, not excluding those with thumbnails. Let's fix this with two practical solutions:
Solution 1: Filter Inside the Function (Quickest Fix)
The simplest approach is to check the blob's full path directly in your function code and exit early if it contains "thumbnails". This avoids any trigger configuration headaches.
Example in C#:
[FunctionName("ProcessProfilePhoto")] public static void Run( [BlobTrigger("ProfilePhoto/{name}", Connection = "AzureWebJobsStorage")] Stream myBlob, string name, string blobTrigger, // Gets the full blob path ILogger log) { // Skip blobs with "thumbnails" in their path if (blobTrigger.Contains("thumbnails", StringComparison.OrdinalIgnoreCase)) { log.LogInformation($"Skipping thumbnail blob: {blobTrigger}"); return; } // Your normal processing logic here log.LogInformation($"Processing blob: {name}"); }
Example in Python:
import logging import azure.functions as func def main(myblob: func.InputStream): # Skip blobs with "thumbnails" in their path if "thumbnails" in myblob.name.lower(): logging.info(f"Skipping thumbnail blob: {myblob.name}") return # Your normal processing logic here logging.info(f"Processing blob: {myblob.name}")
Solution 2: Use Azure Event Grid (Cleaner Long-Term Fix)
If you want to avoid triggering the function entirely for thumbnail blobs, switch to using Azure Event Grid instead of the native Blob Trigger. Event Grid supports filtering rules to exclude specific paths at the source.
Here's how to set it up:
- Create an Event Grid subscription for your storage account, targeting your Azure Function as the endpoint.
- In the subscription's filtering settings, add an exclude filter for the
subjectfield, matching paths that contain/thumbnails/(adjust the pattern to match your exact folder structure). - Only blob creation events that don't include "thumbnails" in their path will now trigger your function.
Why Your Original Configuration Failed
To clarify: Blob Trigger glob patterns have strict rules:
*matches any characters within a single folder (doesn't cross/separators)**matches any characters across multiple folders- There is no built-in syntax for negative matching (excluding paths) directly in the trigger path.
Your original pattern was looking for blobs with the literal string ~thumbnails~ in their path, which isn't what you intended.
内容的提问来源于stack exchange,提问作者Tirupathi Temburu

