2
votes

I have a blob container at Azure blob storage and inside this container there are many directories. Again inside those directories there can be other directories. Now suppose if someone adds a blob to anywhere inside the container, I want the location and blob name. Please help me with your inputs.

I have tried basic blobtrigger azure function, but couldnot make it more.

Thanks in advance

1
you should use an Azure Event Grid eventing feature for azure storage account. docs.microsoft.com/en-us/azure/storage/blobs/… - Roman Kiss
You are supposed to get path/filename with containerName/{name} path setting, what location do you need, relative path under the container or complete url? Also, what language do you use? - Jerry Liu
I am using Java and whole path would be fine..!! I just want to locate the file inside these nested directories. My requirement is whenever new blobs are added to any of subdirectories I should be able to locate them. - Kunal Trivedi
@KunalTrivedi The sample java blob trigger has path = "samples-workitems/{name}" and @BindingName("name") String name, doesn't name give you the dir../filename? could you elaborate whole path, in the format of containerName/dir.../filename or what? - Jerry Liu
@JerryLiu yes thats exactly I would need. containername/dir/filename whenever the file gets uploaded anywhere inside container (under subdirectories too)..!! - Kunal Trivedi

1 Answers

2
votes

Have a try at code below. Metadata name offers blobName, which includes directories and its filename. BlobTrigger offers whole path as you wish, i.e. containerName/blobName.

@FunctionName("BlobTriggerJava")
@StorageAccount("AzureWebJobsStorage")
public void run(
    @BlobTrigger(name = "content", path = "containerName/{name}", dataType = "binary") byte[] content,
    @BindingName("name") String name, @BindingName("BlobTrigger") String wholePath, 
    final ExecutionContext context
) {
    context.getLogger().info("Java Blob trigger function processed a blob. Name: " + name);
    context.getLogger().info("Whole path: " + wholePath);
}