0

I'm new to Azure. I need http triggered function to perform some simple actions on my blob storage. This will be the part of pipeline in datafactory but first I need to figure it out how to edit blobs via functions. I'm stucked now because I have no idea which API/methods I could use. Appreciate for your help. Below is some part of my code.

def main(req):
    logging.info('Python HTTP trigger function processed a request.')
    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        requested_file = requests.get("web address")
        ### Should I connect to blob here?
        with open("file.txt", "wb") as file:
            file.write(requested_file.content)
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )
rarova
  • 23
  • 3
  • https://stackoverflow.com/questions/64776039/read-data-from-azure-blob-storage-in-azure-function-in-python – Thomas Aug 23 '21 at 11:32
  • Does this answer your question? [Read data from Azure blob storage in Azure Function in python](https://stackoverflow.com/questions/64776039/read-data-from-azure-blob-storage-in-azure-function-in-python) – Thomas Aug 23 '21 at 11:32
  • @Thomas Partialy yes. But how Can I do reverse - Download file and save it to blob? – rarova Aug 23 '21 at 11:38
  • download file from where ? – Thomas Aug 23 '21 at 11:53
  • @Thomas Download file from internet (for example some .csv or txt files) via requests library. Then save this on blob. – rarova Aug 23 '21 at 11:56
  • It's not clear specifically what issue you're having, but... Azure Functions have no issue writing to blob storage. As for editing blobs, you cannot edit a blob in-place (unless it's a page blob, which doesn't really fit the scenario here). You'd need to download to working storage (or memory) within your function app, manipulate your data as needed, then upload to a blob. Same with an existing blob - download to local storage, edit, then upload to blob. – David Makogon Aug 24 '21 at 12:05

1 Answers1

0

You can use either the Python SDK

Or use bindings and triggers for Azure Functions

How you would do it is use the bindings to pull in your blob and then use the bindings to write out your blob. This is actually a pretty good example of it:

Similarly with the SDK, you want to make sure that you are calling in and writing out. Make sure all your keys are correct and your containers are too!

Joseph Song
  • 184
  • 1
  • 12