Reading blob using Azure function

Raja 86 Reputation points
2021-10-26T13:03:17.48+00:00

Hi Team,
I've written a Azure function in Python using VCC. I'm able to deploy and run the program in Azure portal. The problem I'm facing is to read the blob/and its content. I've used the http template of Azure function.

I'm using below code to read the content,

containerName = "test1"
        conn_str = ("BlobEndpoint=https://mydev.blob.core.windows.net/sandbox/test1/random?sp=r&st=2021-10-26T12:36:21Z&se=2021-10-26T20:36:21Z&spr=https&sv=2020-08-04&sr=b&sig=M1WCxkqcHdzRaFjkJOZmbU2%2Bj9yhQu416%2FkXaEYBCm0%3D")
        blob_service_client = BlobServiceClient.from_connection_string(conn_str)
        container_client = blob_service_client.get_container_client(containerName)
        blob_client=container_client.get_blob_client("random")
        stream_loader = blob_client.download_blob()

        filereader = json.loads(stream_loader.readall)
        a_file = open("fileReader.json","w")
        a_file = json.dump(filereader,a_file)
        with open("fileReader.json", 'r',encoding='utf-8-sig') as f:
                data = json.load(f)

blob_list = container_client.list_blobs()
        for blob in blob_list:
            print("\t" + blob.name)
            with open("fileReader.json", 'r',encoding='utf-8-sig') as f:
                data = json.load(f)

The connection string I'm using above is created using "Generate SAS" option. Please correct if this is not the right approach.

Also when I run this I get below error,

2021-10-26T12:40:05Z   [Information]   CORS policy execution failed.
2021-10-26T12:40:05Z   [Information]   Request origin https://functions.azure.com does not have permission to access the resource.

Could you please help me in getting the things right.

Thanks,
Raja

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Samara Soucy - MSFT 5,141 Reputation points
    2021-10-28T23:36:15.607+00:00

    Can you please check if there are any CORS policies set on the storage account you are trying to access?

    144628-image.png

    0 comments No comments

Your answer

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