Share via

Is there an Azure blob matadata autofill functionality?

S-A 25 Reputation points
2024-01-03T07:47:17.25+00:00

I have a blob container that contains multiple folders in it, and I'm using a Search Service to index and then query that data. I want to apply a filter on my search to only be able to retrieve the files in a specific folder in the blob. Is there a way to do that?

I have tried manually setting a new metadata field (let's call it folder_name) and set the value in it to the name of the folder containing the data file I'm targetting and it worked. However, I need a more automated way to do this.

Is there a way to automatically fill a file's metadata field with the name of the folder containing this file through the Azure portal? I basically want any file that gets uploaded to a folder on the blob to have a metadata field filled with its folder name automatically upon upload.

Here's an example flow:

  • The file is uploaded on Azure blob container inside a specific folder (for example "reports")
  • the metadata of the file is then edited so that a new metadata field called "folder_name" is created and has the value "reports" assigned.

If that's possible through the portal please let me know, if not but it's possible in C# that would also be helpful. And if there's an easier workaround for the search filtering that would also be great!

Azure AI Search
Azure AI Search

An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.

Azure AI services
Azure AI services

A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

{count} votes

2 answers

Sort by: Most helpful
  1. Bryan Trach 17,842 Reputation points Microsoft Employee Moderator
    2024-01-04T01:08:22.0933333+00:00

    @S-A Thank you for the great answer from @Luke Murray . I am going to expand upon their answer a little further.

    Yes, it is possible to automatically fill a file's metadata field with the name of the folder containing the file through the Azure portal. You can use Azure Blob Storage triggers to achieve this.

    Here's how you can do it:

    1. Create a new Azure Function App in the Azure portal.
    2. Add a new Blob trigger to the function app. This will allow the function to be triggered whenever a new blob is added to the container.
    3. In the function code, you can use the blob's path to extract the folder name and then update the blob's metadata with the folder name.
    4. Save and publish the function.

    Once the function is published, it will be triggered whenever a new blob is added to the container. The function will extract the folder name from the blob's path and update the blob's metadata with the folder name.

    Regarding your search filtering requirement, you can use the "metadata_storage_path" field to filter the search results based on the folder name. For example, if you want to retrieve all the blobs in the "reports" folder, you can use the following filter expression:

    search=*&$filter=metadata_storage_path eq '/reports/'
    

    This will retrieve all the blobs in the "reports" folder. You can modify the filter expression to retrieve blobs from other folders as well.


  2. Luke Murray 11,521 Reputation points MVP Volunteer Moderator
    2024-01-03T08:42:03.91+00:00

    To use the Portal, you would have to recreate the index, as part of the index creation, it asks what Blob Folder to use.

    User's image

    You can edit the JSON file however for an index already existing: Define the data store.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.