0

while running the code locally using Visual Studio Code - all is working well and the file is saved the to cloud (blob storage).

when deploying to the cloud as function app, files are not saved

blob_service_client = BlobServiceClient.from_connection_string(connection_string)

blob_client = blob_service_client.get_blob_client(container=container_name, blob=file_name)

blob_client.upload_blob(csv_bytes, overwrite=True)

Any hints or solution? thanks.

chewy
  • 8,207
  • 6
  • 42
  • 70
  • Do you have any logs available? My guess would be that the azure function does not have write permissions for the blob storage. – Silvan Jul 01 '23 at 19:17
  • Can you put in the full code how you are retrieving the connection string? Are you sure it is picking the connection string from the application settings? have you defined it there? – Anupam Chand Jul 02 '23 at 06:19

1 Answers1

1

I have reproduced in my environment and got expected results as below:

Firstly, have uploaded from local using function app:

init.py:

import logging
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, __version__
import os
import azure.functions as func


def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request Rithwik.')

    data = "This is Rithwik Bojja"
    conname="rithcon"
    constring="DefaultEndpointsProtocol=https;AccountName=rithwik;AccountKey=pPBW9jWu77Sqp5kA==;EndpointSuffix=core.windows.net"
    blsc = BlobServiceClient.from_connection_string(constring)
    nameblob = "rithblob"
    blc = blsc.get_blob_client(container=conname, blob=nameblob)
    blc.upload_blob(data, overwrite=True)

    return func.HttpResponse(f"Hello, Rithwik File is Send to Blob Storage.")

Output in Local:

enter image description here

enter image description here

enter image description here

After Deploying to Azure and running successfully:

enter image description here

Output:

enter image description here

enter image description here

This is the process if you are giving connection string inside main file.

If you are providing connection string in function.json then you need to add that connection string in Portal . You should add connection string in Configuration Section of Azure Function App(Reference for adding in Configuration section)

enter image description here

Then it works.

Try to follow above process and you will definitely get created blob as I got created.

RithwikBojja
  • 5,069
  • 2
  • 3
  • 7